python
at the command prompt. If the answer shows something like that, then Python is installed: Python 3.7.3 (default, Mar 27 2019, 17:13:21)
[MSC v.1915 64 bit (AMD64)] :: Anaconda custom (64-bit) on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
If it is not installed, or you have Python version 3.4 or younger installed, you need to go to “Download and Install Python”, find the manual for your OS, and follow the instructions. Python 3 does not require a database. This version of Python comes with a built-in SQLite database. This is a lightweight database that is suitable for Django development. If you need to deploy the application in a production environment, however, you’ll need a more advanced solution: PostgreSQL, MySQL, or Oracle. You can learn more about how to make a database work with Django at this link: https://docs.djangoproject.com/en/2.0/topics/install/#database-installation.
Creating a virtual Python environment
We recommend using virtualenv
to create a virtual Python environment so that you can safely use different versions of packages for different projects. This is more practical than installing Python packages directly into the system. Another advantage of virtualenv
is that you don’t need admin rights to install Python packages. Run the following command at the command line to install virtualenv
:
pip install virtualenv
After installing virtualenv
, create a virtual environment using the following command:
virtualenv my_env
This will create the my_env
folder along with the Python environment. Any Python libraries installed with the virtual Python environment activated will be installed in the my_env/lib/python3.7/site-packages
folder.
If Python 2.X was preinstalled on your system and you installed Python 3.X, you must specify
virtualenv
to work with the latest version. You can specify the path where Python 3 is installed and use it to create a virtual environment using the following commands:
$ which python3 /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
$ virtualenv my_env -p
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Use the following command to activate the virtual environment:
source my_env/bin/activate
The command line will include the name of the active virtual environment in brackets:
(my_env) username:~$
deactivate
command is used to deactivate
the virtual environment.More about virtualenv
can be found at https://virtualenv.pypa.io/en/latest/. You can also use virtualenvwrapper
on top of virtualenv
. This tool provides shells that make it easier to create and manage virtual environments. You can download it here: https://virtualenvwrapper.readthedocs.io/en/latest/.
Installing Django with pip
The pip
package management system is the recommended way to install Django. It is pre-installed in Python 3.6+. Use the following command in the shell to install Django using pip:
pip install Django==2.0.5
Django will install into the Python folder named site-packages/
of the active virtual environment. Now you need to check if the installation was successful. To do this, enter python
at the command line, import Django, and check its version as follows:
>>> import django
>>> django.get_version( )
'2.0.5'
If the output is like the one above, then Django has been successfully installed on your computer:
Django can also be installed in other ways. A full installation guide can be found here: https://docs.djangoproject.com/en/2.0/topics/install/
.