pip install django error

2020-02-14 10:41发布

I'm trying to install django using pip in Terminal.

I always get an exception, however. The last error is always "permission denied", and I do not understand why. Any help is appreciated.

Log:

pip install django
You are using pip version 7.1.0, however version 8.1.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting django
  Using cached Django-1.9.4-py2.py3-none-any.whl
Installing collected packages: django
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/basecommand.py", line 223, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/commands/install.py", line 299, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 813, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/req/req_install.py", line 1008, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/wheel.py", line 310, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-7.1.0-py2.7.egg/pip/utils/__init__.py", line 70, in ensure_dir
    os.makedirs(path)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'

3条回答
我想做一个坏孩纸
2楼-- · 2020-02-14 11:05
sudo pip install django 

The error tells you that you can't access a directory (you don't have enough permissions), so you can gain root access via sudo to get the permissions.

查看更多
Animai°情兽
3楼-- · 2020-02-14 11:19

My Solution for [Errno 13] Permission denied:

Target: To install package into system/virtualenv

Why you get this problem? Because apart from root, other users you created don't have permission to write to site-packages, that is why you get OS error permission denied for that user

How to solve?

Make sure you activated the virtualenv all the time

Source bin/activate

Suppose, I created a user

(sampleEnv) sunny@ubuntu-512mb-lon1-01: pip install django

This will give the Permission error, Instead of that shift to root

$ su -

(sampleEnv) root@ubuntu-512mb-lon1-01: pip install django

Now root have permission to write to site-packages.

Once django is installed. Shift back to user

$ su - sunny

then do pip freeze you can see packages installed in system and go on!

查看更多
我命由我不由天
4楼-- · 2020-02-14 11:26

pip should be run by a user which has permissions to write to site-packages directory (in your case, /Library/Python/2.7/site-packages/). You should either run it from the root user or under sudo.

查看更多
登录 后发表回答