windows.txt 5.1 KB

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