1. ================================
    
  2. How to install Django on Windows
    
  3. ================================
    
  4. 
    
  5. .. highlight:: doscon
    
  6. 
    
  7. This document will guide you through installing Python 3.8 and Django on
    
  8. Windows. It also provides instructions for setting up a virtual environment,
    
  9. which makes it easier to work on Python projects. This is meant as a beginner's
    
  10. guide for users working on Django projects and does not reflect how Django
    
  11. should be installed when developing patches for Django itself.
    
  12. 
    
  13. The steps in this guide have been tested with Windows 10. In other
    
  14. versions, the steps would be similar. You will need to be familiar with using
    
  15. the Windows command prompt.
    
  16. 
    
  17. .. _install_python_windows:
    
  18. 
    
  19. Install Python
    
  20. ==============
    
  21. 
    
  22. Django is a Python web framework, thus requiring Python to be installed on your
    
  23. machine. At the time of writing, Python 3.8 is the latest version.
    
  24. 
    
  25. To install Python on your machine go to https://www.python.org/downloads/. The
    
  26. website should offer you a download button for the latest Python version.
    
  27. Download the executable installer and run it. Check the boxes next to "Install
    
  28. launcher for all users (recommended)" then click "Install Now".
    
  29. 
    
  30. After installation, open the command prompt and check that the Python version
    
  31. matches the version you installed by executing::
    
  32. 
    
  33.     ...\> py --version
    
  34. 
    
  35. .. seealso::
    
  36. 
    
  37.     For more details, see :doc:`python:using/windows` documentation.
    
  38. 
    
  39. About ``pip``
    
  40. =============
    
  41. 
    
  42. `pip`_ is a package manager for Python and is included by default with the
    
  43. Python installer. It helps to install and uninstall Python packages
    
  44. (such as Django!). For the rest of the installation, we'll use ``pip`` to
    
  45. install Python packages from the command line.
    
  46. 
    
  47. .. _pip: https://pypi.org/project/pip/
    
  48. 
    
  49. .. _virtualenvironment:
    
  50. 
    
  51. Setting up a virtual environment
    
  52. ================================
    
  53. 
    
  54. It is best practice to provide a dedicated environment for each Django project
    
  55. you create. There are many options to manage environments and packages within
    
  56. the Python ecosystem, some of which are recommended in the `Python
    
  57. documentation <https://packaging.python.org/guides/tool-recommendations/>`_.
    
  58. Python itself comes with :doc:`venv <python:tutorial/venv>` for managing
    
  59. environments which we will use for this guide.
    
  60. 
    
  61. To create a virtual environment for your project, open a new command prompt,
    
  62. navigate to the folder where you want to create your project and then enter the
    
  63. following::
    
  64. 
    
  65.     ...\> py -m venv project-name
    
  66. 
    
  67. This will create a folder called 'project-name' if it does not already exist
    
  68. and set up the virtual environment. To activate the environment, run::
    
  69. 
    
  70.     ...\> project-name\Scripts\activate.bat
    
  71. 
    
  72. The virtual environment will be activated and you'll see "(project-name)" next
    
  73. to the command prompt to designate that. Each time you start a new command
    
  74. prompt, you'll need to activate the environment again.
    
  75. 
    
  76. Install Django
    
  77. ==============
    
  78. 
    
  79. Django can be installed easily using ``pip`` within your virtual environment.
    
  80. 
    
  81. In the command prompt, ensure your virtual environment is active, and execute
    
  82. the following command::
    
  83. 
    
  84.     ...\> py -m pip install Django
    
  85. 
    
  86. This will download and install the latest Django release.
    
  87. 
    
  88. After the installation has completed, you can verify your Django installation
    
  89. by executing ``django-admin --version`` in the command prompt.
    
  90. 
    
  91. See :ref:`database-installation` for information on database installation
    
  92. with Django.
    
  93. 
    
  94. Colored terminal output
    
  95. =======================
    
  96. 
    
  97. A quality-of-life feature adds colored (rather than monochrome) output to the
    
  98. terminal. In modern terminals this should work for both CMD and PowerShell. If
    
  99. for some reason this needs to be disabled, set the environmental variable
    
  100. :envvar:`DJANGO_COLORS` to ``nocolor``.
    
  101. 
    
  102. On older Windows versions, or legacy terminals, colorama_ must be installed to
    
  103. enable syntax coloring::
    
  104. 
    
  105.     ...\> py -m pip install colorama
    
  106. 
    
  107. See :ref:`syntax-coloring` for more information on color settings.
    
  108. 
    
  109. .. _colorama: https://pypi.org/project/colorama/
    
  110. 
    
  111. Common pitfalls
    
  112. ===============
    
  113. 
    
  114. * If ``django-admin`` only displays the help text no matter what arguments
    
  115.   it is given, there is probably a problem with the file association in
    
  116.   Windows. Check if there is more than one environment variable set for
    
  117.   running Python scripts in ``PATH``. This usually occurs when there is more
    
  118.   than one Python version installed.
    
  119. 
    
  120. * If you are connecting to the internet behind a proxy, there might be problems
    
  121.   in running the command ``py -m pip install Django``. Set the environment
    
  122.   variables for proxy configuration in the command prompt as follows::
    
  123. 
    
  124.     ...\> set http_proxy=http://username:password@proxyserver:proxyport
    
  125.     ...\> set https_proxy=https://username:password@proxyserver:proxyport
    
  126. 
    
  127. * In general, Django assumes that ``UTF-8`` encoding is used for I/O. This may
    
  128.   cause problems if your system is set to use a different encoding. Recent
    
  129.   versions of Python allow setting the :envvar:`PYTHONUTF8` environment
    
  130.   variable in order to force a ``UTF-8`` encoding. Windows 10 also provides a
    
  131.   system-wide setting by checking ``Use Unicode UTF-8 for worldwide language
    
  132.   support`` in :menuselection:`Language --> Administrative Language Settings
    
  133.   --> Change system locale` in system settings.