2
0

windows.txt 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ================================
  2. How to install Django on Windows
  3. ================================
  4. This document will guide you through installing Python 3.13 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.13 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. .. admonition:: ``py`` is not recognized or found
  26. Depending on how you've installed Python (such as via the Microsoft Store),
  27. ``py`` may not be available in the command prompt.
  28. You will then need to use ``python`` instead of ``py`` when entering
  29. commands.
  30. .. seealso::
  31. For more details, see :doc:`python:using/windows` documentation.
  32. About ``pip``
  33. =============
  34. :pypi:`pip` is a package manager for Python and is included by default with the
  35. Python installer. It helps to install and uninstall Python packages
  36. (such as Django!). For the rest of the installation, we'll use ``pip`` to
  37. install Python packages from the command line.
  38. .. _virtualenvironment:
  39. Setting up a virtual environment
  40. ================================
  41. It is best practice to provide a dedicated environment for each Django project
  42. you create. There are many options to manage environments and packages within
  43. the Python ecosystem, some of which are recommended in the `Python
  44. documentation <https://packaging.python.org/guides/tool-recommendations/>`_.
  45. Python itself comes with :doc:`venv <python:tutorial/venv>` for managing
  46. environments which we will use for this guide.
  47. To create a virtual environment for your project, open a new command prompt,
  48. navigate to the folder where you want to create your project and then enter the
  49. following:
  50. .. code-block:: doscon
  51. ...\> py -m venv project-name
  52. This will create a folder called 'project-name' if it does not already exist
  53. and set up the virtual environment. To activate the environment, run:
  54. .. code-block:: doscon
  55. ...\> project-name\Scripts\activate.bat
  56. The virtual environment will be activated and you'll see "(project-name)" next
  57. to the command prompt to designate that. Each time you start a new command
  58. prompt, you'll need to activate the environment again.
  59. Install Django
  60. ==============
  61. Django can be installed easily using ``pip`` within your virtual environment.
  62. In the command prompt, ensure your virtual environment is active, and execute
  63. the following command:
  64. .. code-block:: doscon
  65. ...\> py -m pip install Django
  66. This will download and install the latest Django release.
  67. After the installation has completed, you can verify your Django installation
  68. by executing ``django-admin --version`` in the command prompt.
  69. See :ref:`database-installation` for information on database installation
  70. with Django.
  71. Colored terminal output
  72. =======================
  73. A quality-of-life feature adds colored (rather than monochrome) output to the
  74. terminal. In modern terminals this should work for both CMD and PowerShell. If
  75. for some reason this needs to be disabled, set the environmental variable
  76. :envvar:`DJANGO_COLORS` to ``nocolor``.
  77. On older Windows versions, or legacy terminals, :pypi:`colorama` 0.4.6+ must be
  78. installed to enable syntax coloring:
  79. .. code-block:: doscon
  80. ...\> py -m pip install "colorama >= 0.4.6"
  81. See :ref:`syntax-coloring` for more information on color settings.
  82. Common pitfalls
  83. ===============
  84. * If ``django-admin`` only displays the help text no matter what arguments
  85. it is given, there is probably a problem with the file association in
  86. Windows. Check if there is more than one environment variable set for
  87. running Python scripts in ``PATH``. This usually occurs when there is more
  88. than one Python version installed.
  89. * If you are connecting to the internet behind a proxy, there might be problems
  90. in running the command ``py -m pip install Django``. Set the environment
  91. variables for proxy configuration in the command prompt as follows:
  92. .. code-block:: doscon
  93. ...\> set http_proxy=http://username:password@proxyserver:proxyport
  94. ...\> set https_proxy=https://username:password@proxyserver:proxyport
  95. * In general, Django assumes that ``UTF-8`` encoding is used for I/O. This may
  96. cause problems if your system is set to use a different encoding. Recent
  97. versions of Python allow setting the :envvar:`PYTHONUTF8` environment
  98. variable in order to force a ``UTF-8`` encoding. Windows 10 also provides a
  99. system-wide setting by checking ``Use Unicode UTF-8 for worldwide language
  100. support`` in :menuselection:`Language --> Administrative Language Settings
  101. --> Change system locale` in system settings.