我正在关注这篇文章,以便为所有 virtualenvs 制定一个 ipython 规则。
据我了解,这篇文章的主要思想是,当在 virtualenv 中时,ipython 找不到它的模块。
(a-virtualenv)me@pc:~$ ipython
Traceback (most recent call last):
File "/usr/bin/ipython", line 19, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
ImportError: No module named IPython.frontend.terminal.ipapp
为了解决这个问题,我将它添加到我的 /usr/bin/ipython
import sys
if "/usr/lib/python2.7/dist-packages" not in sys.path:
sys.path.append("/usr/lib/python2.7/dist-packages")
这个技巧适用于巴尔萨泽。但就我而言,我明白了
Traceback (most recent call last):
File "/usr/bin/ipython", line 18, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 46, in <module>
from .frontend.terminal.embed import embed
File "/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/embed.py", line 37, in <module>
from IPython.frontend.terminal.ipapp import load_default_config
File "/usr/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.py", line 38, in <module>
from IPython.core.completer import IPCompleter
File "/usr/lib/python2.7/dist-packages/IPython/core/completer.py", line 84, in <module>
from IPython.utils import generics
File "/usr/lib/python2.7/dist-packages/IPython/utils/generics.py", line 19, in <module>
from IPython.external.simplegeneric import generic
File "/usr/lib/python2.7/dist-packages/IPython/external/simplegeneric/__init__.py", line 4, in <module>
from _simplegeneric import *
ImportError: No module named _simplegeneric
我想也许我也应该/usr/lib/python2.7/dist-packages/IPython/external
加入sys.path
。/usr/bin/ipython
我得到的是
Traceback (most recent call last):
File "/usr/bin/ipython", line 18, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
File "/usr/lib/python2.7/dist-packages/IPython/__init__.py", line 43, in <module>
from .config.loader import Config
File "/usr/lib/python2.7/dist-packages/IPython/config/loader.py", line 27, in <module>
from IPython.utils.path import filefind, get_ipython_dir
File "/usr/lib/python2.7/dist-packages/IPython/utils/path.py", line 24, in <module>
from IPython.utils.process import system
File "/usr/lib/python2.7/dist-packages/IPython/utils/process.py", line 27, in <module>
from ._process_posix import _find_cmd, system, getoutput, arg_split
File "/usr/lib/python2.7/dist-packages/IPython/utils/_process_posix.py", line 27, in <module>
from IPython.utils import text
File "/usr/lib/python2.7/dist-packages/IPython/utils/text.py", line 27, in <module>
from IPython.external.path import path
ImportError: cannot import name path
此错误发生在 的第 43 行IPython/__init__py
,但前一个错误发生在第 46 行。
如何使 ipython 与 virtualenv 一起工作?
如何添加
/usr/lib/python2.7/dist-packages/IPython/external
到sys.path
导致新的错误?为了更好地理解 python 导入路径,我应该阅读什么?
谢谢!
PS:正常的 IPython sys.path
['',
'/usr/bin',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-client',
'/usr/lib/python2.7/dist-packages/ubuntuone-control-panel',
'/usr/lib/python2.7/dist-packages/ubuntuone-couch',
'/usr/lib/python2.7/dist-packages/ubuntuone-installer',
'/usr/lib/python2.7/dist-packages/ubuntuone-storage-protocol',
'/usr/lib/python2.7/dist-packages/IPython/extensions']