I can't seem to use sudo pip install correctly so that it installs into the following directory:
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
so that I can then import the module using python
I've run
sudo pip install scikit-learn --upgrade
Result
Requirement already up-to-date: scikit-learn in /usr/local/lib/python2.7/site-packages
Cleaning up...
However, it's not in the correct directory
How do I get sudo pip install to install into correct directory?
In addition, I've tried
sudo pip install Scrappy
I get the following message
new-host-2:site-packages Chris$ sudo pip install Scrapy
Password:
Requirement already satisfied (use --upgrade to upgrade): Scrapy in /usr/local/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): Twisted>=10.0.0 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): w3lib>=1.8.0 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): queuelib in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): lxml in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): zope.interface>=3.6.0 in /usr/local/lib/python2.7/site-packages (from Twisted>=10.0.0->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cryptography>=0.2.1 in /usr/local/lib/python2.7/site-packages (from pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): setuptools in /usr/local/lib/python2.7/site-packages (from zope.interface>=3.6.0->Twisted>=10.0.0->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cffi>=0.8 in /usr/local/lib/python2.7/site-packages (from cryptography>=0.2.1->pyOpenSSL->Scrapy)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/local/lib/python2.7/site-packages (from cffi>=0.8->cryptography>=0.2.1->pyOpenSSL->Scrapy)
Both these instances demonstrate that it's been installed but not correctly. For example, when I run the following import in python:
import scrapy
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-6-51c73a18167b> in <module>()
----> 1 import scrapy
ImportError: No module named scrapy
I've tried the following:
sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
I totally agree with the guys, it's better to use virtualenv so you can set a custom environment for every project. It ideal for maintenance because it's like a different world for every project and every update of an application you make won't interfere with other projects.
Here you can find a nutshell of virtualenv related to installation and first steps.
1 - Something that might work
The
pip
executable is actually a Python script.By default it contains (on Linux):
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: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:or
depending on your setup.
2 - What you should do
pip
was not thought of as something thatroot
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 asPATH
on Linux) and then installpip
withoutsudo
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.This is what worked for me on Windows. The cause being multiple python installations
python -m pip uninstall pip setuptools