IPython的导入失败和一般蟒蛇的sys.path(IPython import failure

2019-06-26 10:30发布

我下面这个职位做一个IPython的一统virtualenvs。

据我了解,该职位的主要思想是,在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/externalsys.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上的前一个发生。

  1. 我怎样才能让IPython中使用的virtualenv工作?

  2. 怎样才能加入/usr/lib/python2.7/dist-packages/IPython/externalsys.path产生的新的错误?

  3. 我应该怎么读更好地了解蟒蛇进口路径的?

谢谢!

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

Answer 1:

IPython的似乎是现在的工作!

因为IPython中找不到simplegeneric。 我试图找到simplegeneric,发现simplegeneric是“/usr/lib/pymodules/python2.7”。 添加“/usr/lib/pymodules/python2.7”后,IPython中工作正常。

杰夫Tratner的评论确实有帮助!



Answer 2:

如果安装ipython3使用apt-get ,你就不会遇到这样的任何问题。

取而代之的ipython ,应键入ipython3在终端上。

对于Python 2使用ipython2



Answer 3:

在更改路径以任何方式没有帮助。 但是运行IPython的超级用户的工作(虽然我不骄傲呢!)

sudo ipython


Answer 4:

pip install ipython ,而不是apt-get install ipython 。 前者安装到virtualenv中,后者安装到系统Python包。



Answer 5:

我有同样的问题,在我的情况下它的原因是,目录:在创建虚拟环境时/usr/lib/python2.7/dist-packages没有添加到路径(我想知道为什么)

在终端下我的情况下解决了这个问题:

workon 'your_environment_here'
add2virtualenv /usr/lib/python2.7/dist-packages

注意:这里假设你正在使用virtualenvwrapper



Answer 6:

就我而言,这是一个包上涨名为“路径”这是从引起导入错误我定制的Python路径:

import IPython.external.path as path

见https://github.com/ipython/ipython/issues/3994



Answer 7:

我经历了一个新的ubuntu主机的一些怪事,并意识到我是在Mac上获得不同的行为为mkvirtualenv与Ubuntu的。 我过去与此不同

'mkvirtualenv --system-site-packages mynewenv'


Answer 8:

对我来说,解决办法是从0.13.2 升级的IPython到目前最新的4.0.0。



Answer 9:

类似traceback我经历了python 3.5.4pip 10.0.1安装后ipython成功。

line 32, in <module>
from .debugger import TerminalPdb, Pdb
File "/usr/lib/python3.5/site-packages/IPython/terminal/debugger.py", line 6, in <module>
    from IPython.core.completer import IPCompleter
File "/usr/lib/python3.5/site-packages/IPython/core/completer.py", line 137, in <module>
    from IPython.utils import generics
File "/usr/lib/python3.5/site-packages/IPython/utils/generics.py", line 8, in <module>
from simplegeneric import generic
ImportError: No module named 'simplegeneric'

更新或安装simplegenericsudo pip install simplegeneric --upgrade我得到

要求已经达到最新:simplegeneric在/usr/lib/python3.5/site-packages(0.8.1)

一些最初的试验后,我搜索在谷歌/计算器,看看有没有人遇到过类似的问题,发现了这个。 而其@zjk答案,帮助我找到解决办法。

解决方案:只发现egg中的文件夹python3.5安装包目录。 所以,我把他们赶走,并全新安装simplegeneric

sudo rm -rf /usr/lib/python3.5/site-packages/simplegeneric-0.8.1-py3.5.egg-info/
sudo pip install simplegeneric

之后IPython的工作就像魅力。

注:我安装的软件包在系统级,这就是为什么sudo需要。



文章来源: IPython import failure and python sys.path in general