Pip installs packages in the wrong directory with

2019-07-18 11:01发布

问题:

With Python 3.7 on OS X I set up a virtual environment then

    $ source venv/bin/activate
    $ pip install numpy
    $ which pip 
pip is /Users/me/PycharmProjects/Test1/venv/bin/pip
(venv) 

But rather than installing in the virtual environment numpy is installed in

/usr/local/lib/python2.7

and numpy doesn't appear in pip list

The issue occurs with both Python installed via the Python download or via brew.

What possible settings could be causing the package to be installed in the wrong location.

回答1:

To answer my own question.

There was an invisible

~/.config/pip/pip.conf 

file. That contained these lines:

[global]
target = /usr/local/lib/python2.7/site-packages

This file was a few years old, so I'm unsure how it got there but removing it resolved the issue.