{"title":"如何在Windows上安装Django","version":"2.0","locale":"zh-hans","docname":"howto/windows","url":"/zh-hans/2.0/howto/windows/","canonical":"https://djangodocs.dev/zh-hans/2.0/howto/windows/","summary":"This document will guide you through installing Python 3.5 and Django on Windows. It also provides instructions for installing virtualenv and virtualenvwrapper ,…","html":"<h1>如何在Windows上安装Django<a class=\"heading-anchor\" href=\"#how-to-install-django-on-windows\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h1>\n<p>This document will guide you through installing Python 3.5 and Django on\nWindows. It also provides instructions for installing <a class=\"reference external\" href=\"https://pypi.org/project/virtualenv/\">virtualenv</a> and\n<a class=\"reference external\" href=\"https://pypi.org/project/virtualenvwrapper-win/\">virtualenvwrapper</a>, which make it easier to work on Python projects. This is\nmeant as a beginner's guide for users working on Django projects and does not\nreflect how Django should be installed when developing patches for Django\nitself.</p>\n<p>The steps in this guide have been tested with Windows 7, 8, and 10. In other\nversions, the steps would be similar. You will need to be familiar with using\nthe Windows command prompt.</p>\n<section id=\"install-python\">\n<h2>安装Python<a class=\"heading-anchor\" href=\"#install-python\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django 是一个 Python Web 框架，因此需要在您的机器上安装 Python。在本文撰写时，Python 最新的版本是 3.5。</p>\n<p>To install Python on your machine go to <a class=\"reference external\" href=\"https://python.org/downloads/\">https://python.org/downloads/</a>. The\nwebsite should offer you a download button for the latest Python version.\nDownload the executable installer and run it. Check the box next to <code class=\"docutils literal notranslate\"><span class=\"pre\">Add</span>\n<span class=\"pre\">Python</span> <span class=\"pre\">3.5</span> <span class=\"pre\">to</span> <span class=\"pre\">PATH</span></code> and then click <code class=\"docutils literal notranslate\"><span class=\"pre\">Install</span> <span class=\"pre\">Now</span></code>.</p>\n<p>After installation, open the command prompt and check that the Python version\nmatches the version you installed by executing:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">python</span> <span class=\"o\">--</span><span class=\"n\">version</span>\n</code></pre></div>\n</section>\n<section id=\"about-pip\">\n<h2>关于 <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span></code><a class=\"heading-anchor\" href=\"#about-pip\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference external\" href=\"https://pypi.org/project/pip/\">pip</a> is a package manage for Python. It makes installing and uninstalling\nPython packages (such as Django!) very easy. For the rest of the installation,\nwe'll use <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span></code> to install Python packages from the command line.</p>\n<p>想要在您的机器上安装 pip，请转至 <a class=\"reference external\" href=\"https://pip.pypa.io/en/latest/installing/\">https://pip.pypa.io/en/latest/installing/</a>，并按照“Installing with get-pip.py”说明进行操作</p>\n</section>\n<section id=\"install-virtualenv-and-virtualenvwrapper\">\n<h2>安装 <code class=\"docutils literal notranslate\"><span class=\"pre\">virtualenv</span></code> 和 <code class=\"docutils literal notranslate\"><span class=\"pre\">virtualenvwrapper</span></code><a class=\"heading-anchor\" href=\"#install-virtualenv-and-virtualenvwrapper\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p><a class=\"reference external\" href=\"https://pypi.org/project/virtualenv/\">virtualenv</a> and <a class=\"reference external\" href=\"https://pypi.org/project/virtualenvwrapper-win/\">virtualenvwrapper</a> provide a dedicated environment for\neach Django project you create. While not mandatory, this is considered a best\npractice and will save you time in the future when you're ready to deploy your\nproject. Simply type:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">pip</span> <span class=\"n\">install</span> <span class=\"n\">virtualenvwrapper</span><span class=\"o\">-</span><span class=\"n\">win</span>\n</code></pre></div>\n<p>然后为您的项目创建一个虚拟环境:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">mkvirtualenv</span> <span class=\"n\">myproject</span>\n</code></pre></div>\n<p>The virtual environment will be activated automatically and you'll see\n&quot;(myproject)&quot; next to the command prompt to designate that. If you start a new\ncommand prompt, you'll need to activate the environment again using:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">workon</span> <span class=\"n\">myproject</span>\n</code></pre></div>\n</section>\n<section id=\"install-django\">\n<h2>安装Django<a class=\"heading-anchor\" href=\"#install-django\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<p>Django可以轻松地在你的虚拟环境中使用``pip``安装</p>\n<p>In the command prompt, ensure your virtual environment is active, and execute\nthe following command:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"n\">pip</span> <span class=\"n\">install</span> <span class=\"n\">django</span>\n</code></pre></div>\n<p>这将下载并安装最新的Django版本。</p>\n<p>After the installation has completed, you can verify your Django installation\nby executing <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span> <span class=\"pre\">--version</span></code> in the command prompt.</p>\n<p>See <a class=\"reference internal\" href=\"/zh-hans/2.0/topics/install/#database-installation\"><span class=\"std std-ref\">Get your database running</span></a> for information on database installation\nwith Django.</p>\n</section>\n<section id=\"common-pitfalls\">\n<h2>Common pitfalls<a class=\"heading-anchor\" href=\"#common-pitfalls\"><span class=\"visually-hidden\">Link to this heading</span><span aria-hidden=\"true\">#</span></a></h2>\n<ul>\n<li><p>If <code class=\"docutils literal notranslate\"><span class=\"pre\">django-admin</span></code> only displays the help text no matter what arguments\nit is given, there is probably a problem with the file association in\nWindows. Check if there is more than one environment variable set for\nrunning Python scripts in <code class=\"docutils literal notranslate\"><span class=\"pre\">PATH</span></code>. This usually occurs when there is more\nthan one Python version installed.</p></li>\n<li><p>If you are connecting to the internet behind a proxy, there might be problem\nin running the command <code class=\"docutils literal notranslate\"><span class=\"pre\">pip</span> <span class=\"pre\">install</span> <span class=\"pre\">django</span></code>. Set the environment variables\nfor proxy configuration in the command prompt as follows:</p>\n<div class=\"code-block\" data-language=\"default\"><div class=\"code-block-toolbar\"><span class=\"code-block-language\">Code</span><button type=\"button\" class=\"copy-button\" data-copy hidden><span class=\"copy-button-label\">Copy</span></button></div><pre role=\"group\" tabindex=\"0\" aria-label=\"Code code\"><code><span class=\"nb\">set</span> <span class=\"n\">http_proxy</span><span class=\"o\">=</span><span class=\"n\">http</span><span class=\"p\">:</span><span class=\"o\">//</span><span class=\"n\">username</span><span class=\"p\">:</span><span class=\"n\">password</span><span class=\"nd\">@proxyserver</span><span class=\"p\">:</span><span class=\"n\">proxyport</span>\n<span class=\"nb\">set</span> <span class=\"n\">https_proxy</span><span class=\"o\">=</span><span class=\"n\">https</span><span class=\"p\">:</span><span class=\"o\">//</span><span class=\"n\">username</span><span class=\"p\">:</span><span class=\"n\">password</span><span class=\"nd\">@proxyserver</span><span class=\"p\">:</span><span class=\"n\">proxyport</span>\n</code></pre></div>\n</li>\n</ul>\n</section>","rootId":"how-to-install-django-on-windows","toc":[{"title":"安装Python","anchor":"install-python","children":[]},{"title":"关于 pip","anchor":"about-pip","children":[]},{"title":"安装 virtualenv 和 virtualenvwrapper","anchor":"install-virtualenv-and-virtualenvwrapper","children":[]},{"title":"安装Django","anchor":"install-django","children":[]},{"title":"Common pitfalls","anchor":"common-pitfalls","children":[]}],"breadcrumbs":[{"docname":"howto/index","title":"\"How-to\" guides","url":"/zh-hans/2.0/howto/"}],"prev":{"docname":"howto/static-files/deployment","title":"Deploying static files","url":"/zh-hans/2.0/howto/static-files/deployment/"},"next":{"docname":"howto/writing-migrations","title":"Writing database migrations","url":"/zh-hans/2.0/howto/writing-migrations/"},"formats":{"html":"/zh-hans/2.0/howto/windows/","markdown":"/zh-hans/2.0/howto/windows.md","json":"/zh-hans/2.0/howto/windows.json"},"source":"https://github.com/django/django/blob/stable/2.0.x/docs/howto/windows.txt","official":"https://docs.djangoproject.com/zh-hans/2.0/howto/windows/","inVersions":["6.1","6.0","5.2","5.1","5.0","4.2","4.1","4.0","3.2","3.1","3.0","2.2","2.1","2.0"],"inLocales":["en","zh-hans","fr","ja","id","pt-br","ko","es","el","pl"]}