简体   繁体   中英

Deploy Django on Python 3.6.2

I have downloaded Python 3.6.2 (64 bit) in Windows 10 (64 bit). Now I want to work on Django framework so I want to download Django using pip command but it shows 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. 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

The best way to work with Django is within a virtual environment. Installing packages in your system's Python 3.6 will affect all programs you have running on Python 3.6; if you have multiple Django apps, your requirements could get all mixed up.

Django works really nicely with virtual environments: there's a good tutorial here . Essentially, you want to set up a virtual environment for each project, and then install Django (and its dependencies) cleanly within that environment. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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