Jupyter无法启动,“ ImportError:此程序包不可访问”

时间:2018-10-30 09:46:15

标签: python ubuntu jupyter-notebook

我无法在Linux机器上启动Jupyter笔记本服务器。键入jupyter notebook时,出现以下错误:

ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
During handling of the above exception, another exception occurred:
ModuleNotFoundError: No module named 'urlparse'

以下是一些系统信息,如果有其他帮助,请告诉我:

$ jupyter --version
4.4.0

$ which jupyter
/usr/bin/jupyter

$ which python
/usr/bin/python

$ which python3
/usr/bin/python3

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

$ cat /proc/version
Linux version 4.15.0-38-generic (buildd@lcy01-amd64-023) (gcc version 7.3.0 (Ubuntu 7.3.0-16ubuntu3)) #41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018

$ pip3 --version
pip 9.0.1 from /usr/local/lib/python3.6/dist-packages (python 3.6)

尝试python2 -m pip install urlparse --user时出现错误:Collecting urlparse Could not find a version that satisfies the requirement

报告的错误类似于the one shown here,但是陈述的创建和使用python3虚拟环境的解决方案似乎不能立即修复jupyter notebook命令,尽管它确实替代了pythonpython3可执行文件,带有指向虚拟环境的链接:

(env) $ which jupyter
/usr/bin/jupyter
(env) $ which python
/home/.../env/bin/python
(env) $ which python3
/home/.../env/bin/python3

万一有关于python路径的疑问,这里是python 2的路径:

$ ipython
...
In [2]: sys.path
Out[2]: 
['/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/$USER/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/home/$USER/.local/lib/python2.7/site-packages/IPython/extensions',
 '/home/$USER/.ipython']

对于python3

$ ipython3
...
In [2]: sys.path                                                                                                                                 
Out[2]: 
['/usr/lib/python36.zip',
 '/usr/lib/python3.6',
 '/usr/lib/python3.6/lib-dynload',
 '/home/$USER/.local/lib/python3.6/site-packages',
 '/usr/local/lib/python3.6/dist-packages',
 '/usr/lib/python3/dist-packages',
 '/home/$USER/.local/lib/python3.6/site-packages/IPython/extensions',
 '/home/$USER/.ipython']

启动Jupyter时第一个错误的完整堆栈跟踪为:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/notebook/nbextensions.py", line 18, in <module>
    from urllib.request import urlretrieve
  File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
    import http.client
  File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
    raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

/usr/bin/jupyter的内容如下:

$ cat `which jupyter`
#!/usr/bin/python3
# EASY-INSTALL-ENTRY-SCRIPT: 'jupyter-core==4.4.0','console_scripts','jupyter'
__requires__ = 'jupyter-core==4.4.0'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('jupyter-core==4.4.0', 'console_scripts', 'jupyter')()
    )

一个建议的答案是存在一个伪造的http库,“ 它恰好被/home/$USER/.local/lib/python3中的某些第三方模块“ http”覆盖.6 / site-packages / http ”。当我手动删除该库时,现在出现导入site模块的错误,如下所示:

$ cd /home/$USER/.local/lib/python3.6/site-packages
$ mv ./http ~/Desktop/python_disabled/python3/
$ jupyter notebook
Error processing line 1 of /home/$USER/.local/lib/python3.6/site-packages/lazr.restfulclient-0.14.0-py3.6-nspkg.pth:

Failed to import the site module
Traceback (most recent call last):
  File "/usr/lib/python3.6/site.py", line 174, in addpackage
    exec(line)
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.6/types.py", line 171, in <module>
    import functools as _functools
  File "/usr/lib/python3.6/functools.py", line 21, in <module>
    from collections import namedtuple
  File "/usr/lib/python3.6/collections/__init__.py", line 32, in <module>
    from reprlib import recursive_repr as _recursive_repr
  File "/home/$USER/.local/lib/python3.6/site-packages/reprlib/__init__.py", line 7, in <module>
    raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.

1 个答案:

答案 0 :(得分:1)

这部分是错误的:

  File "/usr/lib/python3.6/urllib/request.py", line 88, in <module>
    import http.client
  File "/home/$USER/.local/lib/python3.6/site-packages/http/__init__.py", line 7, in <module>
    raise ImportError('This package should not be accessible on Python 3. '

标准模块尝试导入http.client,也导入a standard module。在您的安装中,它恰好被http上的某些第三方模块“ /home/$USER/.local/lib/python3.6/site-packages/http”覆盖。

删除该第三方模块。


在更新的问题中卸载reprlib后,根据与http软件包相同的问题判断,您似乎在/home/$USER/.local/lib/python3.6中安装了the micropython-lib set of packages因为它们很多,所以删除整个目录会更容易。我不知道它们的最终结局,因为它们不仅与常规的CPython安装不兼容,而且与Python 3一般不兼容


最后,请注意,depending on your needs, using virtualenv may be a more manageable solution than pip --user.