我通常使用IPython,并且最近才注意到常规python shell中导入的搜索路径是错误的。根据我的理解,sys.path继承自PYTHONPATH(尽管我不知道PYTHONPATH在哪里生活),这在IPython中是不同的?我担心这个有影响的装置。比如我刚试过
pip install --upgrade gensim
失败了,因为它无法解决我已安装的scipy依赖项。 所以我在Ipython中找到了更深入的鸽子
import gensim
gensim.__version__
返回.9.1 而在python中
import gensim
gensim.__version__
返回.8.9
以下是Ipython版本的sys.path的样子:
['',
'/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']
和常规python脚本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']
答案 0 :(得分:3)
现在可能为时已晚,但这里的答案也可能对您有所帮助:ipython reads wrong python version。基本上,ipython脚本可以直接引用特定的python二进制文件,而不是你直接运行python时获得的那个。
答案 1 :(得分:0)
我的mac上安装了一个brew版本的Python。由于某些原因,无法使用系统库。在brew uninstall python
之后它再次起作用,因为默认的python被切换回/ usr / bin / python。
还可以使用which python
,which ipython
并打开/ usr / bin / python,/ usr / local / bin / python,/ usr / bin / ipython和/ usr / local / bin / ipython并在那里进行导入可能会帮助您找出它确实出错的地方。
答案 2 :(得分:0)
您可能已激活虚拟环境,忽略系统路径。
可以通过在终端中运行它来修复它(关闭笔记本等之后):
virtualenv --system-site-packages ~