windows.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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://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. Common pitfalls
  65. ===============
  66. * If ``django-admin`` only displays the help text no matter what arguments
  67. it is given, there is probably a problem with the file association in
  68. Windows. Check if there is more than one environment variable set for
  69. running Python scripts in ``PATH``. This usually occurs when there is more
  70. than one Python version installed.
  71. * If you are connecting to the internet behind a proxy, there might be problems
  72. in running the command ``py -m pip install Django``. Set the environment
  73. variables for proxy configuration in the command prompt as follows::
  74. ...\> set http_proxy=http://username:password@proxyserver:proxyport
  75. ...\> set https_proxy=https://username:password@proxyserver:proxyport