简体   繁体   English

在Python 3.6.2上部署Django

[英]Deploy Django on Python 3.6.2

I have downloaded Python 3.6.2 (64 bit) in Windows 10 (64 bit). 我在Windows 10(64位)中下载了Python 3.6.2(64位)。 Now I want to work on Django framework so I want to download Django using pip command but it shows Error. 现在我想开发Django框架,所以我想使用pip命令下载Django,但它显示Error。

C:\Windows\system32>pip install django
Collecting django
  Using cached Django-1.11.4-py2.py3-none-any.whl
Collecting pytz (from django)
  Using cached pytz-2017.2-py2.py3-none-any.whl
Installing collected packages: pytz, django

Exception: 例外:

Traceback (most recent call last):
      File "c:\program files\python36\lib\site-packages\pip\basecommand.py", line 215, in main
        status = self.run(options, args)
      File "c:\program files\python36\lib\site-packages\pip\commands\install.py", line 342, in run
        prefix=options.prefix_path,
      File "c:\program files\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
        **kwargs
      File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 851, in install
        self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
      File "c:\program files\python36\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
        isolated=self.isolated,
      File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
        clobber(source, lib_dir, True)
      File "c:\program files\python36\lib\site-packages\pip\wheel.py", line 316, in clobber
        ensure_dir(destdir)
      File "c:\program files\python36\lib\site-packages\pip\utils\__init__.py", line 83, in ensure_dir
        os.makedirs(path)
      File "c:\program files\python36\lib\os.py", line 220, in makedirs
        mkdir(name, mode)
    PermissionError: [WinError 5] Access is denied: 'c:\\program files\\python36\\Lib\\site-packages\\pytz'

The problem has to do with the location you have chosen to install python, normally it's installed in C:\\pythonXX but your installation is in C:\\Program Files\\pythonXX. 问题与您选择安装python的位置有关,通常它安装在C:\\ pythonXX中,但您的安装位于C:\\ Program Files \\ pythonXX中。 That is always going to cause problems, you will need to always be running it as administrator. 这总是会导致问题,您需要始终以管理员身份运行它。 Quick and best solution, uninstall and accept to install python on the default location - C:\\pythonXX 快速和最佳解决方案,卸载并接受在默认位置安装python - C:\\ pythonXX

The best way to work with Django is within a virtual environment. 使用Django的最佳方式是在虚拟环境中。 Installing packages in your system's Python 3.6 will affect all programs you have running on Python 3.6; 在系统的Python 3.6中安装软件包将影响在Python 3.6上运行的所有程序; if you have multiple Django apps, your requirements could get all mixed up. 如果你有多个Django应用程序,你的要求可能会混淆。

Django works really nicely with virtual environments: there's a good tutorial here . Django的作品真的很好地与虚拟环境:有一个很好的教程在这里 Essentially, you want to set up a virtual environment for each project, and then install Django (and its dependencies) cleanly within that environment. 实际上,您希望为每个项目设置一个虚拟环境,然后在该环境中干净地安装Django(及其依赖项)。 This should avoid any "Access denied" or other errors that you're experiencing. 这应该避免任何“拒绝访问”或您遇到的其他错误。

Just as an example of how virtual environments help: if you need to use different versions of Django for different apps, they should be limited only to apps within that same virtual environment. 仅作为虚拟环境如何帮助的示例:如果您需要为不同的应用程序使用不同版本的Django,它们应仅限于同一虚拟环境中的应用程序。 Then, you can install the package differently in a different environment for another app. 然后,您可以在另一个应用程序的不同环境中以不同方式安装该程序包。 That way, when you "import django" from one of your apps, you know you're getting the version you need. 这样,当您从某个应用程序“导入django”时,您就知道自己获得了所需的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM