3

I'm working on a server that I don't have admin privileges to so I've installed packages locally pip --user. In order to get python to see this path I added this to my .profile:

export PYTHONPATH=$PYTHONPATH:/Users/delavega/Library/Python/2.7/lib/python/site-packages

This successfully adds locally installed packages to python's path as evidenced by calling sys.path(). However, IPython does not use the packages from the local install and instead uses the globally installed package in: /usr/local/lib/python2.7/site-packages

Printing the paths for python and IPython, my local site-packages folder is in both but in different places and the paths overall differ:

Python:

['',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/statsmodels-0.6.0-py2.7-macosx-10.8-x86_64.egg',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-2.2-py2.7.egg',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/statsmodels-0.6.0-py2.7-macosx-10.8-x86_64.egg',
 '/usr/local/lib/python2.7/site-packages/setuptools-2.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg',
 '/Users/delavega',
 '/Users/delavega/Library/Python/2.7/lib/python/site-packages',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
 '/Library/Python/2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages']

IPython:

['',
 '/usr/local/lib/python2.7/site-packages/statsmodels-0.6.0-py2.7-macosx-10.8-x86_64.egg',
 '/usr/local/lib/python2.7/site-packages/setuptools-2.2-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg',
 '/usr/local/lib/python2.7/site-packages',
 '/usr/local/bin',
 '/usr/local/lib/python2.7/site-packages/pip-1.5.4-py2.7.egg',
 '/Users/delavega',
 '/Users/delavega/Library/Python/2.7/lib/python/site-packages',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Library/Python/2.7/site-packages',
 '/usr/local/lib/python2.7/site-packages/IPython/extensions']

As you can see, the paths are different. Appending or prepending IPython's path using sys does not change which package is loaded

Why are these paths different and how can I get IPython to load from my local install?

aleph4
  • 708
  • 1
  • 8
  • 15

1 Answers1

0

The most surefire method to ensure that ipython is virtualenv-aware is to install it with pip into your virtualenv.

There are certainly ipython_config.py hacks (http://rodesia.org/2012/09/04/making-ipython-virtualenv-aware/) to attempt to give it some awareness, but YMMV.

Six
  • 5,122
  • 3
  • 29
  • 38