pip install pkg给出Permission denied:/Library/Python/2.7/site-packages/pkg

时间:2017-08-09 08:19:33

标签: python macos python-2.7 homebrew

今天有趣的人在使用brew reinstall python在自制程序上重新安装Python 2之后。

异常

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/commands/install.py", line 342, in run
    prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_set.py", line 784, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/req/req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/wheel.py", line 316, in clobber
    ensure_dir(destdir)
  File "/Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg/pip/utils/__init__.py", line 83, 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/urllib3’

相关内容

$ which python
/usr/local/bin/python

$ echo $PYTHONPATH
$

很确定这是使用OS X系统Python,但无法解决问题。

1 个答案:

答案 0 :(得分:1)

好的 - 自制软件让我在重新安装后使用pip2而不是pip

我可能应该阅读文档,但无论如何这不是主要问题......

现在是文件/usr/local/bin/pip的第一行 #!/usr/local/opt/python/bin/python2.7

这就是问题所在。将此行更改为:

一个。 #!/usr/local/bin/python

B中。 #!`brew --prefix`/bin/python

解决了这个问题。

注意:我不能100%责怪自制软件。请注意这里发生了什么,但问题已经解决了。

此外,我可以运行sudo pip ...,但这会与macOS系统site-packages目录混乱,这通常被认为不是一个好主意。