pip3崩溃导入错误

时间:2018-04-02 10:23:23

标签: python linux python-3.x pip

Python 3.5.2

Ubuntu 16.04 LTS

尝试使用pip3安装一些软件包,无论参数如何都会返回以下内容:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 33, in vendored
    __import__(vendored_name, globals(), locals(), level=0)
ImportError: No module named 'pip._vendor.pkg_resources'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
  File "/usr/lib/python3/dist-packages/pip/__init__.py", line 13, in <module>
    from pip.exceptions import InstallationError, CommandError, PipError
  File "/usr/lib/python3/dist-packages/pip/exceptions.py", line 6, in <module>
    from pip._vendor.six import iteritems
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 75, in <module>
    vendored("pkg_resources")
  File "/usr/lib/python3/dist-packages/pip/_vendor/__init__.py", line 36, in vendored
    __import__(modulename, globals(), locals(), level=0)
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2927, in <module>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2913, in _call_aside
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 956, in subscribe
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2952, in <lambda>
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2515, in activate
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2097, in declare_namespace
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2047, in _handle_ns
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
AttributeError: '_NamespacePath' object has no attribute 'sort'

我试图通过重新安装python3-pip来修复它:

sudo apt install --reinstall python3-pip

但这没有帮助。

我收集它与我安装的软件包有关,这些软件包是使用ls /usr/lib/python3/dist-packages生成的:

alabaster
alabaster-0.7.7.egg-info
apport
apport_python_hook.py
apt
aptdaemon
apt_inst.cpython-35m-x86_64-linux-gnu.so
apt_pkg.cpython-35m-x86_64-linux-gnu.so
aptsources
AptUrl
apturl-0.5.2.egg-info
babel
Babel-1.3.egg-info
beautifulsoup4-4.4.1.egg-info
blinker
blinker-1.3.egg-info
Brlapi-0.6.4.egg-info
brlapi.cpython-35m-x86_64-linux-gnu.so
bs4
cairo
_cffi_backend.cpython-35m-x86_64-linux-gnu.so
chardet
chardet-2.3.0.egg-info
checkbox_support
checkbox_support-0.22.egg-info
CommandNotFound
command_not_found-0.3.egg-info
cryptography
cryptography-1.2.3.egg-info
cups.cpython-35m-x86_64-linux-gnu.so
cupsext.cpython-35m-x86_64-linux-gnu.so
cupshelpers
curl
cycler-0.9.0.egg-info
cycler.py
dateutil
dbus
_dbus_bindings.cpython-35m-x86_64-linux-gnu.so
_dbus_glib_bindings.cpython-35m-x86_64-linux-gnu.so
deb822.py
debconf.py
debian
debian_bundle
decorator-4.0.6.egg-info
decorator.py
defer
defer-1.0.6.egg-info
DistUpgrade
docutils
docutils-0.12.egg-info
easy_install.py
feedparser-5.1.3.egg-info
feedparser.py
feedparser_sgmllib3.py
gi
guacamole
guacamole-0.9.2.egg-info
hpmudext.cpython-35m-x86_64-linux-gnu.so
html5lib
html5lib-0.999.egg-info
httplib2
httplib2-0.9.1.egg-info
idna
idna-2.0.egg-info
IPython
ipython-2.4.1.egg-info
janitor
jedi
jedi-0.9.0.egg-info
jinja2
Jinja2-2.8.egg-info
jwt
LanguageSelector
language_selector-0.1.egg-info
language_support_pkgs.py
louis
louis-2.6.4.egg-info
lsb_release.py
lxml
lxml-3.5.0.egg-info
mako
Mako-1.0.3.egg-info
markupsafe
MarkupSafe-0.23.egg-info
matplotlib
matplotlib-1.5.1.egg-info
matplotlib-1.5.1-nspkg.pth
mpl_toolkits
numexpr
numexpr-2.4.3.egg-info
numpy
numpy-1.11.0.egg-info
NvidiaDetector
oauthlib
oauthlib-1.0.3.egg-info
Onboard
onboard-1.2.0.egg-info
orca
padme
padme-1.1.1.egg-info
pandas
pandas-0.17.1.egg-info
pcardext.cpython-35m-x86_64-linux-gnu.so
pep8-1.7.0.egg-info
pep8.py
pexpect
pexpect-4.0.1.egg-info
PIL
Pillow-3.1.2.egg-info
pip
pip-8.1.1.egg-info
pkg_resources
plainbox
plainbox-0.25.egg-info
ply
ply-3.7.egg-info
problem_report.py
psutil
psutil-3.4.2.egg-info
ptyprocess
ptyprocess-0.5.egg-info
pyasn1
pyasn1-0.1.9.egg-info
pyatspi
__pycache__
pycups-1.9.73.egg-info
pycurl-7.43.0.egg-info
pycurl.cpython-35m-x86_64-linux-gnu.so
pyflakes
pyflakes-1.1.0.egg-info
pygments
Pygments-2.1.egg-info
pygobject-3.20.0.egg-info
pygtkcompat
PyJWT-1.3.0.egg-info
pylab.py
pyparsing-2.0.3.egg-info
pyparsing.py
PyQt4
python_apt-1.1.0.b1_ubuntu0.16.04.1.egg-info
python_dateutil-2.4.2.egg-info
python_debian-0.1.27.egg-info
python_systemd-231.egg-info
pytz
pytz-2014.10.egg-info
pyxdg-0.25.egg-info
pyzmq-15.2.0.egg-info
Quirks
reportlab
reportlab-3.3.0.egg-info
requests
requests-2.9.1.egg-info
roman-2.0.0.egg-info
roman.py
scanext.cpython-35m-x86_64-linux-gnu.so
scipy
scipy-0.17.0.egg-info
sessioninstaller
sessioninstaller-0.0.0.egg-info
setuptools
setuptools-20.7.0.egg-info
simplegeneric-0.8.1.egg-info
simplegeneric.py
sipconfig_nd5.py
sipconfig.py
sip.cpython-35m-x86_64-linux-gnu.so
six-1.10.0.egg-info
six.py
softwareproperties
speechd
speechd_config
sphinx
Sphinx-1.3.6.egg-info
sphinx_rtd_theme
sphinx_rtd_theme-0.1.9.egg-info
spyder-2.3.8.egg-info
spyderlib
spyderplugins
systemd
system_service-0.3.egg-info
tables
tables-3.2.2.egg-info
UbuntuDrivers
ubuntu_drivers_common-0.0.0.egg-info
UbuntuSystemService
ufw
ufw-0.35.egg-info
unattended_upgrades-0.1.egg-info
unity_scope_calculator-0.1.egg-info
unity_scope_chromiumbookmarks-0.1.egg-info
unity_scope_colourlovers-0.1.egg-info
unity_scope_devhelp-0.1.egg-info
unity_scope_firefoxbookmarks-0.1.egg-info
unity_scope_gdrive-0.7.egg-info
unity_scope_manpages-0.1.egg-info
unity_scope_openclipart-0.1.egg-info
unity_scope_texdoc-0.1.egg-info
unity_scope_tomboy-0.1.egg-info
unity_scope_virtualbox-0.1.egg-info
unity_scope_yelp-0.1.egg-info
unity_scope_zotero-0.1.egg-info
unohelper.py
uno.py
UpdateManager
urllib3
urllib3-1.13.1.egg-info
usbcreator
usb_creator-0.3.0.egg-info
wheel
wheel-0.29.0.egg-info
xdg
xdiagnose
xdiagnose-3.8.4.1.egg-info
xkit
xkit-0.0.0.egg-info
xlsxwriter
XlsxWriter-0.7.3.egg-info
zmq

我不完全确定错误的来源。

4 个答案:

答案 0 :(得分:2)

尝试sudo apt install --reinstall python3-pkg-resources python3-setuptools。 虽然pkg_resources中通常包含setuptools,但Debian和Ubuntu的那些人为它保留了一个单独的包。

如果这样做无效,请尝试以下命令在您的主目录中设置更新的setuptools(包括pkg_resources):

mkdir upgrade-setuptools
cd upgrade-setuptools
cat > usercustomize.py <<EOF
try:
    import setuptools
except ImportError:
    import setuptools
pip3 install --user -U setuptools pip
cd ..
rm upgrade-setuptools/usercustomize.py
rmdir upgrade-setuptools

根据https://github.com/pypa/setuptools/issues/885#issuecomment-266583177,导入setuptools两次应解决此问题。

答案 1 :(得分:0)

尝试:

python -m pip install --upgrade setuptools

答案 2 :(得分:0)

我遇到了类似的问题。这似乎与错误#4330#4216有关。在这两个链接中,各种各样的人们都提到了对他们有用的解决方案。在后一个链接上发布了一条建议之后,解决我的问题的命令是:

-jailshell: fork: Resource temporarily unavailable

答案 3 :(得分:0)

就我而言,我已将Ubuntu从16.04升级到18.04。 在升级Anaconda之前,我没有运气就尝试了上述所有建议:

conda update --all