Ipython与python有不同的sys.path并且不使用PYTHONPATH?

时间:2012-08-30 20:30:46

标签: python ipython pythonpath

似乎IPython没有考虑我的PYTHONPATH,而普通的python解释器就是这样做的。我在Windows 7上。

我的PYTHONPATH: C:\工作空间\蟒; C:\ Python27 \ LIB \站点包\ spyderlib; C:\工作区\的Python \ awesim \ awesim

打印sys.path:

import sys
for i in sorted(sys.path):
    print i

这是我在IPython中获得的:

C:\ JModelica.org-1.8 \的Python C:\ Python27 C:\ Python27 \的DLL C:\ Python27 \ lib中 C:\ Python27 \ LIB \ LIB-TK C:\ Python27 \ LIB \高原双赢 C:\ Python27 \ LIB \站点包 C:\ Python27 \ LIB \站点包\ PIL C:\ Python27 \ LIB \站点包\ PythonWin的 C:\ Python27 \ LIB \站点包\ IPython中-0.13 py2.7.egg C:\ Python27 \ LIB \站点包\ IPython中-0.13 py2.7.egg \ IPython的\扩展 C:\ Python27 \ LIB \站点包\ numpy的-1.6.2-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ openpyxl-1.5.8-py2.7.egg C:\ Python27 \ LIB \站点包\大熊猫-0.8.1-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ pyzmq-2.2.0.1-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ setuptools的-0.6c11-py2.7.egg-信息 C:\ Python27 \ LIB \站点包\狮身人面像-1.1.3-py2.7.egg C:\ Python27 \ LIB \站点包\ statsmodels-0.4.0-py2.7-win32.egg C:\ Python27 \ LIB \站点包\龙卷风2.3 py2.7.egg C:\ Python27 \ LIB \站点包\ WIN32 C:\ Python27 \ LIB \站点包\ WIN32 \ LIB C:\ Python27 \ LIB \站点包\ WX-2.8-MSW-unicode的 C:\ Python27 \脚本 C:\ Windows \ System32下\ python27.zip

在python控制台中也一样:

C:\ Python27 C:\ Python27 \的DLL C:\ Python27 \ LIB \站点包\ spyderlib C:\ Python27 \ lib中 C:\ Python27 \ LIB \ LIB-TK C:\ Python27 \ LIB \高原双赢 C:\ Python27 \ LIB \站点包 C:\ Python27 \ LIB \站点包\ PIL C:\ Python27 \ LIB \站点包\ PythonWin的 C:\ Python27 \ LIB \站点包\ IPython中-0.13 py2.7.egg C:\ Python27 \ LIB \站点包\ numpy的-1.6.2-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ openpyxl-1.5.8-py2.7.egg C:\ Python27 \ LIB \站点包\大熊猫-0.8.1-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ pyzmq-2.2.0.1-py2.7-win32.egg C:\ Python27 \ LIB \站点包\ setuptools的-0.6c11-py2.7.egg-信息 C:\ Python27 \ LIB \站点包\狮身人面像-1.1.3-py2.7.egg C:\ Python27 \ LIB \站点包\ statsmodels-0.4.0-py2.7-win32.egg C:\ Python27 \ LIB \站点包\龙卷风2.3 py2.7.egg C:\ Python27 \ LIB \站点包\ WIN32 C:\ Python27 \ LIB \站点包\ WIN32 \ LIB C:\ Python27 \ LIB \站点包\ WX-2.8-MSW-unicode的 C:\工作区\ Python的\ awesim \ awesim C:\ WINDOWS \ SYSTEM32 \ python27.zip C:\工作空间\蟒

你可以看到普通的python控制台反映了PYTHONPATH,但是IPython输出没有。

事先感谢你的线索。

3 个答案:

答案 0 :(得分:3)

显然,当Python和IPython的sys.paths不同时会发生这种情况。

对于IPython,一些快速的临时解决方案是:

if form.is_valid():
    cd = form.cleaned_data
    cart.add(product=product,
             quantity=cd['quantity'],
             update_quantity=cd['update'],
             size=cd['size'],
             upd_size=cd['sz'])
return redirect('cart:cart_detail')

我个人喜欢把它放在我正在处理的脚本中,以便包含我在项目目录中组织的模块,包括它们的子目录。 (PS。不要​​忘记:如果主目录和所需的子目录包含一个(空的)__init__.py文件,则python会在路径中包含子目录。)

永久的解决方案是创建一个新的IPython配置文件:

import sys
sys.path.append('your paths')

转到ipython个人资料并编辑: profile_default / ipython_config.py

添加以下

ipython profile create
ipython locate
/Users/username/.ipython

这适用于Linux,我也应该可以在Windows上运行。

答案 1 :(得分:2)

从“开始”菜单链接的.exe启动程序是由setuptools创建的,它们可能无法正确设置您的环境(我不太了解Windows环境,无法确定,或者是否可以修复)

但是如果从命令行启动IPython,它肯定会正确地继承你的环境。

答案 2 :(得分:1)

我刚刚在运行Python 2.6的Linux上解决了类似的问题。

事实证明我设置的虚拟环境忽略了系统路径。

通过关闭所有python程序并运行:

来解决这个问题
virtualenv --system-site-packages ~
相关问题