Pip Install not installing into correct directory?
From the comments to the original question, it seems that you have multiple versions of python installed and that pip just goes to the wrong version.
First, to know which version of python you're using, just type which python
. You should either see:
which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
if you're going to the right version of python, or:
which python
/usr/bin/python
If you're going to the 'wrong' version. To make pip go to the right version, you first have to change the path:
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin/python:${PATH}
typing 'which python' would now get you to the right result. Next, install pip (if it's not already installed for this installation of python). Finally, use it. you should be fine now.
This is what worked for me on Windows. The cause being multiple python installations
- update path with correct python
- uninstall pip using
python -m pip uninstall pip setuptools
- restart windows didn't work until a restart
Virtualenv is your friend
Even if you want to add a package to your primary install, it's still best to do it in a virtual environment first, to ensure compatibility with your other packages. However, if you get familiar with virtualenv, you'll probably find there's really no reason to install anything in your base install.
1 - Something that might work
The pip
executable is actually a Python script.
By default it contains (on Linux):
#!/usr/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==1.5.6','console_scripts','pip'
__requires__ = 'pip==1.5.6'
import sys
from pkg_resources import load_entry_point
if __name__ == '__main__':
sys.exit(
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
)
So if you got the same in MacOS, pip
would always use /usr/bin/python
.
But this is a default. You can still provide the version of python you want either by editing the file or by using python explicitly.
If which python
returns /usr/bin/python
then something went wrong when you installed your own version. If it is /Library/Frameworks/Python.framework/Versions/2.7/bin/python
, you can directly call:
sudo python `which pip` install scikit-learn --upgrade
However, chances are high that it won't work. The reason is that sudo
is resetting all your environment variables. To make it work, the easiest would be to use:
sudo -E pip install scikit-learn --upgrade
or
sudo -E python `which pip` install scikit-learn --upgrade
depending on your setup.
2 - What you should do
pip
was not thought of as something that root
should execute. The actual best way to use it is to install a local, non-root, python version. You just have to make sure that you use it by default by setting up the correct environment variables (such as PATH
on Linux) and then install pip
without sudo
using that python version.
An even better way would be to setup virtualenv
s from your root install.
This way, you can install/update whatever you want without root privileges and never bother again about why sudo pip
is not working. You would also avoid to provide root privileges to whatever is on Pypi and that would warrant that you don't mix system libs with your own.