Python和IPython的路径不同 [英] Python and IPython paths differ

查看:297
本文介绍了Python和IPython的路径不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,我没有管理员权限的服务器上,所以我已经安装的软件包本地PIP --user。为了让Python来看看这条道路我说这我的.profile文件:

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

这增加了成功的本地安装包python的路径通过调用sys.path的证明()。然而,IPython的确实的的使用包从本地安装,而是使用全球安装包:/usr/local/lib/python2.7/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

打印Python和IPython的路径,我的本地站点包文件夹在这两个,但在不同的地方和路径不同,整体的:

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的:

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']

正如你所看到的,路径是不同的。追加或使用SYS不会改变其包装prepending IPython的路径

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

为什么这些路径不同,我怎样才能IPython的从加载我的本地安装?

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

推荐答案

要确保IPython的最万无一失的方法是virtualenv中感知是与PIP安装到你的virtualenv。

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

有一定ipython_config.py黑客(的http:// rodesia .ORG / 2012/09/04 /制作-IPython的-的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.

这篇关于Python和IPython的路径不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆