Python: pip tries to install to /bin directory

2019-06-28 05:55发布

I installed python with brew install python

which pip
/usr/local/bin/pip

my PYTHONPATH shows /usr/local/lib/python2.7/site-packages/

However, when I try to install something with pip, it goes to the /bin/ directory as shown below. I want things installed to /usr/local/lib/python2.7/site-packages/. How do I fix this?

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:

So pip already has the basic packages installed to site-packages. However, running the same exact pip to install virtualenv tries to install to /bin/.

标签: python macos pip
2条回答
虎瘦雄心在
2楼-- · 2019-06-28 06:36

For me, there was a setup.cfg file with the following code [install] prefix= Removing the file fixed it for me.

查看更多
爷的心禁止访问
3楼-- · 2019-06-28 06:39

I was running into this same issue when trying to install virtualenv and flask. Turns out I had a .pydistutils.cfg file in my home directory. I remember placing this there not too long ago as a work around for installing something else. Once I removed this file, running pip install continued working as expected.

查看更多
登录 后发表回答