A few python and pip installations, dude, where are my package sites?

As we all know, Mac OS comes with its own pre-installed python.

The recommendation is to leave this alone and use homebrew to install new python on the system.

My problem is that after installing python (and pip) using homebrew, pip installs packages into Mac OS site packages instead of my own. I confirmed that I am running a homegrown pip:

$ which pip /usr/local/bin/pip 

But then when I try to install something that I can, it installs at:

 /lib/python2.7/site-packages 

The pip should be installed in /usr/local/lib/python2.7/site-packages , if I do not miss something to understand.

Surprisingly, checking with -V gives an amazing result:

 pip -V pip 7.1.0 from /usr/local/lib/python2.7/site-packages (python 2.7) 

Starting pip list right after starting pip install does not display the packages that were supposedly installed by it, but got into the wrong site packages.

Adding to this, packages installed on /lib/python2.7/site-packages are not recognized by my $ PYTHONPATH, and therefore I cannot use them.

To add even more confusion, I decided to use virtualenv, but I was amazed that even using pip with active virtualenv, it continued to install in /lib/python2.7/site-packages instead of virtual package sites.

So, somehow I ended up in a home pip that installs packages outside the homebrew sites and the python interpreter, which cannot use the packages installed in pip.

How do you recommend me find the root cause and have a smooth python experience? :)

+7
source share
2 answers

I think that after you activate virtualenv, your python path should point to the location site site in the environments - if it is not activated. Only after you activate it, you run pip so that it is installed in this virtual env site packages. if it is not activated, it will go into any other site packages that it already knows about:

  • Step 1: creating a virtual env
    • a la ... virtualenv venv
    • Do it only once!
  • Step 2: activate life env
    • something like source /venv/bin/activate
    • It needs to be done every time you want to use this virtual environment.
  • Step 3: run pip commands, watch how they are installed in env virtual packages!

If you do step 3 before step 2, you are not actually using the created virtual environment, so all bets are disabled. This is probably the reason the pip is still set to its original location.

Now my general recommendation is to go ahead and use pyenv to install a specific version of python in your /Users/username/.pyenv folder and abandon the standard OSX and homebrew packages. It's simple, and you can easily control the exact version of python to use it when simply issuing a command to change versions.

THEN use virtualenv in python2 or pyvenv if in python3 (not to be confused with pyenv) to create live environments with your own local site packages for storing pip modules. When you activate virtualenv, your $ PYTHONPATH will switch to a specific location.

Then the flow will be as follows:

  • Use pyenv to turn off and switch to the specific python version you want to use - overriding homebrew and OSX version.
  • Create your vitrualen. This will create a basket that will reference the pyenv python stack, which you specified only in the previous step.
  • Activate virtual env and continue.

Take full control of your environment!

0
source

For example, you can try updating pip using the pip install --upgrade pip , which may or may not redirect your path in pips.

The second, and I had to start with this, to set the preferred path to the pip executable in .bash_profile or .zshrc if you use it. You do this (on Mac) by holding Shift+Command+Period to open hidden files, going to the User folder and opening .bash_profile/.zshrc in a text editor. Then add the path / to / bin where the item you want is located. How to export PATH="User/Username/anaconda3/bin:$PATH" or /usr/local/bin or path/to/venv/bin . Whatever code you write at the end, it will overwrite the previous one.

Thirdly, if you do not want to change your pip by default, but want to use a different version for this particular case, just specify the full path to the pip executable, for example /usr/local/bin/pip list or Users/Username/Desktop/venv/bin/pip install module .

0
source

All Articles