我用brew install python
which pip
/usr/local/bin/pip
我的PYTHONPATH
显示/usr/local/lib/python2.7/site-packages/
但是,当我尝试使用pip安装某些东西时,它会转到/bin/
目录,如下所示。我想把东西安装到/usr/local/lib/python2.7/site-packages/
。我该如何解决?
pip install virtualenv
Downloading/unpacking virtualenv
Downloading virtualenv-1.11.6-py2.py3-none-any.whl (1.6MB): 1.6MB downloaded
Installing collected packages: virtualenv
Cleaning up...
Exception:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/commands/install.py", line 283, in run
{....}
File "/usr/local/lib/python2.7/site-packages/pip-1.5.6-py2.7.egg/pip/_vendor/distlib/util.py", line 384, in write_binary_file
with open(path, 'wb') as f:
IOError: [Errno 13] Permission denied: '/bin/virtualenv'
$ pip list
pip (1.5.6)
setuptools (5.4.2)
wsgiref (0.1.2)
$pip show setuptools
---
Name: setuptools
Version: 5.4.2
Location: /usr/local/lib/python2.7/site-packages/setuptools-5.4.2-py2.7.egg
Requires:
所以pip已经为site-packages安装了基本软件包。但是,运行相同的pip以安装virtualenv会尝试安装到/ bin /。
答案 0 :(得分:5)
我在尝试安装virtualenv和flask时遇到了同样的问题。事实证明我的主目录中有一个.pydistutils.cfg
文件。我记得不久前将它放在那里作为安装其他东西的工作。删除此文件后,运行pip install
继续按预期工作。
答案 1 :(得分:1)
对我来说,有一个带有以下代码的setup.cfg文件
[install]
prefix=
删除文件为我修复了它。