windows.txt 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. ================================
  2. How to install Django on Windows
  3. ================================
  4. .. highlight:: doscon
  5. This document will guide you through installing Python 3.7 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 7, 8, and 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
  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.7 is the latest version.
  17. To install Python on your machine go to https://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)`` and ``Add Python 3.7 to PATH`` then
  21. 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 manage for Python. It makes installing and uninstalling
  30. Python packages (such as Django!) very easy. For the rest of the installation,
  31. we'll use ``pip`` to install Python packages from the command line.
  32. To install pip on your machine, go to
  33. https://pip.pypa.io/en/latest/installing/, and follow the ``Installing with
  34. get-pip.py`` instructions.
  35. .. _pip: https://pypi.org/project/pip/
  36. .. _virtualenvironment:
  37. Setting up a virtual environment
  38. ================================
  39. It is best practice to provide a dedicated environment for each Django project
  40. you create. There are many options to manage environments and packages within
  41. the Python ecosystem, some of which are recommended in the `Python
  42. documentation <https://packaging.python.org/guides/tool-recommendations/>`_.
  43. Python itself comes with :doc:`venv <python:tutorial/venv>` for managing
  44. environments which we will use for this guide.
  45. To create a virtual environment for your project, open a new command prompt,
  46. navigate to the folder where you want to create your project and then enter the
  47. following::
  48. ...\> py -m venv project-name
  49. This will create a folder called 'project-name' if it does not already exist
  50. and setup the virtual environment. To activate the environment, run::
  51. ...\> project-name\Scripts\activate.bat
  52. The virtual environment will be activated and you'll see "(project-name)" next
  53. to the command prompt to designate that. Each time you start a new command
  54. prompt, you'll need to activate the environment again.
  55. Install Django
  56. ==============
  57. Django can be installed easily using ``pip`` within your virtual environment.
  58. In the command prompt, ensure your virtual environment is active, and execute
  59. the following command::
  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. Common pitfalls
  67. ===============
  68. * If ``django-admin`` only displays the help text no matter what arguments
  69. it is given, there is probably a problem with the file association in
  70. Windows. Check if there is more than one environment variable set for
  71. running Python scripts in ``PATH``. This usually occurs when there is more
  72. than one Python version installed.
  73. * If you are connecting to the internet behind a proxy, there might be problems
  74. in running the command ``py -m pip install Django``. Set the environment
  75. variables for proxy configuration in the command prompt as follows::
  76. ...\> set http_proxy=http://username:password@proxyserver:proxyport
  77. ...\> set https_proxy=https://username:password@proxyserver:proxyport