I got a project to do only with Python on v.3.4 + and I'm not getting Django running on non-2.7 versions. Does anyone know a link that teaches the whole installation of django in this new version of Python?
I got a project to do only with Python on v.3.4 + and I'm not getting Django running on non-2.7 versions. Does anyone know a link that teaches the whole installation of django in this new version of Python?
Daniel in my GitHub I share the procedures to do this setup.
I suggest you use virtual environments for development because it allows you to use different versions of Django on the same machine in different environments.
I have chosen to use Python 2. However, if you want to use version 3 remove 2 from Path (not 3) and use the Python 3 version command to install virtual environments (you will notice when viewing the instructions).
Next I share the procedure:
Python, Django, and MySQL///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/******
Experienced Python/Django developers often choose to instead run their Python apps within independent Python virtual environments.
These allow developers to have multiple different Django environments on a single computer, allowing them to create new websites (using the latest version of Django)
while still maintaining websites that rely on older versions.
The Django developer team itself recommends that you use Python virtual environments.
That's how this tutorial is going to be about!
******/
0. Access PowerShell as admin
1. Create the main folder in the root:
PS > cd C:\
PS > mkdir PythonProjects
PS > cd PythonProjects
2. a) Get Python 2.7 (32 bits is the one I suggest) - install in your path - (https://www.python.org/downloads/release/python-2712/)
Customize the location: C:\Python27
Once you’ve installed Python,
open up a PowerShell window and type python and press enter
PS C:\PythonProjects> python
This is what you will see:
-------------------
PS C:\PythonProjects> python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.150
Type "help", "copyright", "credits" or "license" for more information.
>>>
------------------- (CTRL + Z to exit the Python prompt)
b) Get Python 3.5.2 (32 bits is the one I suggest) - install off your path - https://www.python.org/downloads/release/python-352/
Customize the location: C:\Python35-32
3. Get Pip
Save the following script as get-pip.py:
--------------
https://bootstrap.pypa.io/get-pip.py (if you can not find it, ask me for a copy)
--------------
PS C:\PythonProjects> python get-pip.py
To check if everything is working, just type pip at the command line:
PS C:\PythonProjects> pip
PS C:\PythonProjects> pip install --upgrade setuptools
PS C:\PythonProjects> pip install ez_setup
4. Install virtualenv and virtualenvwrapper-powershell
PS C:\PythonProjects> pip install virtualenv
PS C:\PythonProjects> pip install virtualenvwrapper-powershell
5. Create, activate and deactivate virtual environment
PS C:\PythonProjects\virtualenvs> virtualenv rrh
PS C:\PythonProjects\virtualenvs> Set-ExecutionPolicy Unrestricted -Force
PS C:\PythonProjects\virtualenvs> rrh\Scripts\activate
(rrh) PS C:\PythonProjects\virtualenvs> deactivate // to put things back to normal.
Note: It's using Python version 2.7. If we want it to use the Python 3.5.2, just run the following command while creating the virtualenv:
PS C:\PythonProjects\virtualenvs> virtualenv --python=c:\Python35-32\python.exe envname
7. Install Django
(rrh) PS C:\PythonProjects\virtualenvs\rrh> pip install django
Start an interactive interpreter by typing
(rrh) PS C:\PythonProjects\virtualenvs\rrh> python
-----------------------------------
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
-----------------------------------
Great. As you can see, version 2.7.12 is installed in this virtualenv -> the version used globally in our machine.
It's great because MySQL-Python is not yet supported in Python-3.0.
(rrh) PS C:\PythonProjects\virtualenvs> cd ..
(rrh) PS C:\PythonProjects\> mkdir rrh
(rrh) PS C:\PythonProjects\> cd rrh
(rrh) PS C:\PythonProjects\rrh> python -m django-admin startproject webapp // we are calling to our project name 'webapp'.
You should now see the project’s folder in our Django directory (C:\PythonProjects\rrh
(rrh) PS C:\PythonProjects\rrh> cd webapp
(rrh) PS C:\PythonProjects\rrh\webapp> dir
(rrh) PS C:\PythonProjects\rrh\webapp> python manage.py //Manage.py is Django’s command line utility; you should see a list of its available subcommands.
(rrh) PS C:\PythonProjects\rrh\webapp> python manage.py runserver //start up Django’s development server.
8. Setup MySQL and Install MySQL-python in your virtualenv
For the MySQL,
Download:
https://dev.mysql.com/downloads/mysql/ (Check Include Bin Directory in Windows PATH box.)
When prompted, set a password for the MySQL root account.
Create database, create a user and grant the user database access.
For the MySQL-Python,
Download: https://pypi.python.org/pypi/MySQL-python/1.2.5
After downloading, do not run the Windows installer.
(rrh) PS C:\PythonProjects\rrh\webapp> cd /PythonProjects
(rrh) PS C:\PythonProjects> mkdir downloads
(rrh) PS C:\PythonProjects> mv -v ~/Downloads/MySQL-python-1.2.5.win32-py2.7.exe /PythonProjects/downloads
(rrh) PS C:\PythonProjects\rrh\webapp> easy_install file://c:/PythonProjects/downloads/MySQL-python-1.2.5.win32-py2.7.exe
(rrh) PS C:\PythonProjects\rrh\webapp> deactivate
9. Setting Django up to use MySQL (https://docs.djangoproject.com/en/dev/ref/databases/#mysql-notes)
open settings.py,
and update the default key in the DATABASES dictionary.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'DB_NAME',
'USER': 'DB_USER',
'PASSWORD': 'DB_PASSWORD',
'HOST': 'localhost', # Or an IP Address that your DB is hosted on
'PORT': '3306',
}
}
PS C:\PythonProjects\rrh\webapp> cd ..
PS C:\PythonProjects\rrh> cd ..
PS C:\PythonProjects> virtualenvs\rrh\Scripts\activate
(rrh) PS C:\PythonProjects> cd rrh/webapp //root of our Django project.
(rrh) PS C:\PythonProjects\rrh\webapp> python manage.py migrate //
You have Python, Django, and MySQL communicating in harmony.
Congratulations!
Let's deactivate our virtualenv and close PowerShell
(rrh) PS C:\PythonProjects\rrh\webapp> deactivate
PS C:\PythonProjects\rrh\webapp> exit
You can find everything here: link