Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip installs packages in the wrong directory with virtualenv

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.

like image 276
Gazzer Avatar asked Oct 15 '25 20:10

Gazzer


2 Answers

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.

like image 169
Gazzer Avatar answered Oct 18 '25 10:10

Gazzer


What worked for me :

  1. I just created a pip.ini file by myself on my venv root folder .
  2. filled that file like this :

[global]

target=D:\Dropbox\online store\django\ve\lib\site-packages

3)after restarting venv, by using this command

python -m pip install <package name>

now I am able to install packages on my venv ( instead of being installed globally )

like image 20
4seasonn Avatar answered Oct 18 '25 10:10

4seasonn