IPython sys.path different from python sys.path
Asked Answered
K

3

7

I generally use IPython and only recently noticed that the the search path for imports is wrong in the regular python shell. From what I understand, sys.path inherits from PYTHONPATH (although I don't know where PYTHONPATH lives), is this different in IPython? I'm worried that this effecting installations. For instance I just tried

pip install --upgrade gensim

which failed because it couldn't resolve the scipy dependency, which I already have installed. So I dove a little bit deeper and found in Ipython

import gensim
gensim.__version__

returns .9.1 while in python

import gensim
gensim.__version__

returns .8.9

Here is what the Ipython version of sys.path looks like:

['',
    '/Users/change/anaconda/bin',
    '/Users/change/anaconda/lib/python2.7/site-packages/pybing-0.12-py2.7.egg',
    '/Users/change/anaconda/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',
    '/Users/change/anaconda/python.app/Contents/lib/python27.zip',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/plat-darwin',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/plat-mac',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/plat-mac/lib-scriptpackages',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/lib-tk',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/lib-old',
    '/Users/change/anaconda/python.app/Contents/lib/python2.7/lib-dynload',
    '/Users/change/anaconda/lib/python2.7/site-packages',
    '/Users/change/anaconda/lib/python2.7/site-packages/PIL',
    '/Users/change/anaconda/lib/python2.7/site-packages/pygoogle',
    '/Users/change/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info',
    '/Users/change/anaconda/lib/python2.7/site-packages/IPython/extensions']

and the regular python script sys.path:

['',
'/Users/change/anaconda/lib/python2.7/site-packages/pybing-0.12-py2.7.egg',
'/Users/change/anaconda/lib/python2.7/site-packages/httplib2-0.8-py2.7.egg',
'/Users/change/anaconda/lib/python27.zip',
'/Users/change/anaconda/lib/python2.7',
'/Users/change/anaconda/lib/python2.7/plat-darwin',
'/Users/change/anaconda/lib/python2.7/plat-mac',
'/Users/change/anaconda/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/change/anaconda/lib/python2.7/lib-tk',
'/Users/change/anaconda/lib/python2.7/lib-old',
'/Users/change/anaconda/lib/python2.7/lib-dynload',
'/Users/change/anaconda/lib/python2.7/site-packages',
'/Users/change/anaconda/lib/python2.7/site-packages/PIL',
'/Users/change/anaconda/lib/python2.7/site-packages/pygoogle',
'/Users/change/anaconda/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info']
Kesley answered 22/4, 2014 at 2:11 Comment(1)
For more about how sys.path works, see this answer https://mcmap.net/q/137241/-where-is-python-39-s-sys-path-initialized-fromArdath
U
3

Probably too late for you now, but the answer here may help you too: ipython reads wrong python version . Basically the ipython script can directly reference a specific python binary rather than the one that you'd get if you just ran python directly.

Usually answered 11/10, 2014 at 18:45 Comment(1)
The first comment under the question of your link helped me.Thomasenathomasin
C
0

I had a brew installed version of Python on my mac. For some reason that couldn't use the system libraries. After brew uninstall python it worked again, because the default python was switched back to /usr/bin/python.

Also playing around with which python, which ipython and opening up /usr/bin/python, /usr/local/bin/python, /usr/bin/ipython and /usr/local/bin/ipython and doing the imports there might help you find out where it is exactly going wrong.

Cia answered 25/2, 2015 at 10:44 Comment(1)
Mac has wierd issues when setting sys.path and sys.executable on macs, because it has to guess at where the actual python executable is; DARWIN doesn't pass the whole path of python to itself. :(Ardath
I
0

You may have your virtual environment activated which is ignoring the system path.

It can be fixed by running this in terminal (After closing notebook etc):

virtualenv --system-site-packages ~
Instable answered 2/4, 2016 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.