2014-03-20 02:38:12 +08:00
|
|
|
================================
|
|
|
|
How to install Django on Windows
|
|
|
|
================================
|
|
|
|
|
2019-04-20 03:15:38 +08:00
|
|
|
.. highlight:: doscon
|
|
|
|
|
2020-06-03 22:28:10 +08:00
|
|
|
This document will guide you through installing Python 3.8 and Django on
|
2020-05-27 17:18:23 +08:00
|
|
|
Windows. It also provides instructions for setting up a virtual environment,
|
|
|
|
which makes it easier to work on Python projects. This is meant as a beginner's
|
|
|
|
guide for users working on Django projects and does not reflect how Django
|
|
|
|
should be installed when developing patches for Django itself.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-06-03 22:28:10 +08:00
|
|
|
The steps in this guide have been tested with Windows 10. In other
|
2015-10-01 22:57:12 +08:00
|
|
|
versions, the steps would be similar. You will need to be familiar with using
|
|
|
|
the Windows command prompt.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-06-03 22:28:10 +08:00
|
|
|
.. _install_python_windows:
|
|
|
|
|
2014-03-20 02:38:12 +08:00
|
|
|
Install Python
|
|
|
|
==============
|
|
|
|
|
|
|
|
Django is a Python web framework, thus requiring Python to be installed on your
|
2020-06-03 22:28:10 +08:00
|
|
|
machine. At the time of writing, Python 3.8 is the latest version.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2021-04-27 19:09:00 +08:00
|
|
|
To install Python on your machine go to https://www.python.org/downloads/. The
|
2016-01-11 01:16:28 +08:00
|
|
|
website should offer you a download button for the latest Python version.
|
2020-06-03 22:28:10 +08:00
|
|
|
Download the executable installer and run it. Check the boxes next to "Install
|
|
|
|
launcher for all users (recommended)" then click "Install Now".
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2015-10-01 22:57:12 +08:00
|
|
|
After installation, open the command prompt and check that the Python version
|
|
|
|
matches the version you installed by executing::
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2019-04-20 03:15:38 +08:00
|
|
|
...\> py --version
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
|
|
|
For more details, see :doc:`python:using/windows` documentation.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2016-01-25 05:26:11 +08:00
|
|
|
About ``pip``
|
|
|
|
=============
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-06-03 22:28:10 +08:00
|
|
|
`pip`_ is a package manager for Python and is included by default with the
|
|
|
|
Python installer. It helps to install and uninstall Python packages
|
|
|
|
(such as Django!). For the rest of the installation, we'll use ``pip`` to
|
|
|
|
install Python packages from the command line.
|
2016-04-16 18:15:18 +08:00
|
|
|
|
2018-04-18 06:19:29 +08:00
|
|
|
.. _pip: https://pypi.org/project/pip/
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
.. _virtualenvironment:
|
2019-04-20 03:15:38 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
Setting up a virtual environment
|
|
|
|
================================
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
It is best practice to provide a dedicated environment for each Django project
|
|
|
|
you create. There are many options to manage environments and packages within
|
|
|
|
the Python ecosystem, some of which are recommended in the `Python
|
|
|
|
documentation <https://packaging.python.org/guides/tool-recommendations/>`_.
|
2020-05-30 03:09:57 +08:00
|
|
|
Python itself comes with :doc:`venv <python:tutorial/venv>` for managing
|
|
|
|
environments which we will use for this guide.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
To create a virtual environment for your project, open a new command prompt,
|
|
|
|
navigate to the folder where you want to create your project and then enter the
|
|
|
|
following::
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
...\> py -m venv project-name
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
This will create a folder called 'project-name' if it does not already exist
|
2021-08-16 03:11:25 +08:00
|
|
|
and set up the virtual environment. To activate the environment, run::
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
...\> project-name\Scripts\activate.bat
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2020-05-27 17:18:23 +08:00
|
|
|
The virtual environment will be activated and you'll see "(project-name)" next
|
|
|
|
to the command prompt to designate that. Each time you start a new command
|
|
|
|
prompt, you'll need to activate the environment again.
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2014-03-20 02:38:12 +08:00
|
|
|
Install Django
|
|
|
|
==============
|
|
|
|
|
2016-04-16 18:15:18 +08:00
|
|
|
Django can be installed easily using ``pip`` within your virtual environment.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2016-04-16 18:15:18 +08:00
|
|
|
In the command prompt, ensure your virtual environment is active, and execute
|
|
|
|
the following command::
|
2015-10-01 22:57:12 +08:00
|
|
|
|
2019-04-20 03:15:38 +08:00
|
|
|
...\> py -m pip install Django
|
2015-10-01 22:57:12 +08:00
|
|
|
|
|
|
|
This will download and install the latest Django release.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
|
|
|
After the installation has completed, you can verify your Django installation
|
2014-07-26 19:21:52 +08:00
|
|
|
by executing ``django-admin --version`` in the command prompt.
|
2014-03-20 02:38:12 +08:00
|
|
|
|
|
|
|
See :ref:`database-installation` for information on database installation
|
|
|
|
with Django.
|
|
|
|
|
2020-11-11 21:27:10 +08:00
|
|
|
Colored terminal output
|
|
|
|
=======================
|
|
|
|
|
2021-01-19 03:32:43 +08:00
|
|
|
.. versionadded:: 3.2
|
2020-11-11 21:27:10 +08:00
|
|
|
|
2021-04-29 17:26:38 +08:00
|
|
|
A quality-of-life feature adds colored (rather than monochrome) output to the
|
|
|
|
terminal. In modern terminals this should work for both CMD and PowerShell. If
|
|
|
|
for some reason this needs to be disabled, set the environmental variable
|
2020-11-11 21:27:10 +08:00
|
|
|
:envvar:`DJANGO_COLORS` to ``nocolor``.
|
|
|
|
|
2021-04-29 17:26:38 +08:00
|
|
|
On older Windows versions, or legacy terminals, colorama_ must be installed to
|
|
|
|
enable syntax coloring::
|
2020-11-11 21:27:10 +08:00
|
|
|
|
|
|
|
...\> py -m pip install colorama
|
|
|
|
|
|
|
|
See :ref:`syntax-coloring` for more information on color settings.
|
|
|
|
|
|
|
|
.. _colorama: https://pypi.org/project/colorama/
|
|
|
|
|
2014-03-20 02:38:12 +08:00
|
|
|
Common pitfalls
|
|
|
|
===============
|
|
|
|
|
2014-07-26 19:21:52 +08:00
|
|
|
* If ``django-admin`` only displays the help text no matter what arguments
|
2014-03-20 02:38:12 +08:00
|
|
|
it is given, there is probably a problem with the file association in
|
|
|
|
Windows. Check if there is more than one environment variable set for
|
|
|
|
running Python scripts in ``PATH``. This usually occurs when there is more
|
|
|
|
than one Python version installed.
|
|
|
|
|
2019-04-20 03:15:38 +08:00
|
|
|
* If you are connecting to the internet behind a proxy, there might be problems
|
|
|
|
in running the command ``py -m pip install Django``. Set the environment
|
2019-04-14 23:02:36 +08:00
|
|
|
variables for proxy configuration in the command prompt as follows::
|
2014-03-20 02:38:12 +08:00
|
|
|
|
2019-04-20 03:15:38 +08:00
|
|
|
...\> set http_proxy=http://username:password@proxyserver:proxyport
|
|
|
|
...\> set https_proxy=https://username:password@proxyserver:proxyport
|
2021-05-13 02:46:01 +08:00
|
|
|
|
|
|
|
* In general, Django assumes that ``UTF-8`` encoding is used for I/O. This may
|
|
|
|
cause problems if your system is set to use a different encoding. Recent
|
|
|
|
versions of Python allow setting the :envvar:`PYTHONUTF8` environment
|
|
|
|
variable in order to force a ``UTF-8`` encoding. Windows 10 also provides a
|
|
|
|
system-wide setting by checking ``Use Unicode UTF-8 for worldwide language
|
|
|
|
support`` in :menuselection:`Language --> Administrative Language Settings
|
|
|
|
--> Change system locale` in system settings.
|