windows.txt 5.2 KB

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