web-dev-qa-db-ja.com

pip3インストールが機能しない-「pip._vendor.pkg_resources」という名前のモジュールはありません

Python 3(Ubuntu))のパッケージをインストールしようとすると、pip3 install packageName (または Sudo pip3 install packageName)、次のエラーメッセージが表示されます。

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'

私は何日も読んでいますが、成功することなく以下を試しました:

  1. 次のコードを使用して、pip3をアンインストールおよび再インストールします。Sudo apt-get remove python3-pip に続く Sudo apt-get install python3-pip。これは、時々pip3はUbuntuに適切にインストールされません。しかし、うまくいきませんでした。
  2. 他の投稿は、それがsslパッケージの問題であり、sslパッケージがPython3でロードされない場合、それが問題であると示唆しました。ただし、次のコマンドではエラーは発生しません:python3 -c "import ssl"
  3. 他の投稿では、問題がrequestsパッケージにあることが示唆されました。その後、Sudo apt-get remove python3-requests に続く Sudo apt-get install python3-requestsも役に立たない。

必要なその他の情報:

  • pip3 --versionは、上記と同じエラーを表示します。
  • dpkg -L python3-pipは次の情報を提供します。

    /.
    /usr
    /usr/lib
    /usr/lib/python3
    /usr/lib/python3/dist-packages
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/PKG-INFO
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/dependency_links.txt
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/not-Zip-safe
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/requires.txt
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/entry_points.txt
    /usr/lib/python3/dist-packages/pip-8.1.1.Egg-info/top_level.txt
    /usr/lib/python3/dist-packages/pip
    /usr/lib/python3/dist-packages/pip/baseparser.py
    /usr/lib/python3/dist-packages/pip/__main__.py
    /usr/lib/python3/dist-packages/pip/req
    /usr/lib/python3/dist-packages/pip/req/req_set.py
    /usr/lib/python3/dist-packages/pip/req/req_install.py
    /usr/lib/python3/dist-packages/pip/req/__init__.py
    /usr/lib/python3/dist-packages/pip/req/req_file.py
    /usr/lib/python3/dist-packages/pip/req/req_uninstall.py
    /usr/lib/python3/dist-packages/pip/index.py
    /usr/lib/python3/dist-packages/pip/status_codes.py
    /usr/lib/python3/dist-packages/pip/utils
    /usr/lib/python3/dist-packages/pip/utils/setuptools_build.py
    /usr/lib/python3/dist-packages/pip/utils/appdirs.py
    /usr/lib/python3/dist-packages/pip/utils/outdated.py
    /usr/lib/python3/dist-packages/pip/utils/ui.py
    /usr/lib/python3/dist-packages/pip/utils/logging.py
    /usr/lib/python3/dist-packages/pip/utils/encoding.py
    /usr/lib/python3/dist-packages/pip/utils/deprecation.py
    /usr/lib/python3/dist-packages/pip/utils/__init__.py
    /usr/lib/python3/dist-packages/pip/utils/filesystem.py
    /usr/lib/python3/dist-packages/pip/utils/hashes.py
    /usr/lib/python3/dist-packages/pip/utils/build.py
    /usr/lib/python3/dist-packages/pip/compat
    /usr/lib/python3/dist-packages/pip/compat/dictconfig.py
    /usr/lib/python3/dist-packages/pip/compat/__init__.py
    /usr/lib/python3/dist-packages/pip/compat/ordereddict.py
    /usr/lib/python3/dist-packages/pip/models
    /usr/lib/python3/dist-packages/pip/models/index.py
    /usr/lib/python3/dist-packages/pip/models/__init__.py
    /usr/lib/python3/dist-packages/pip/vcs
    /usr/lib/python3/dist-packages/pip/vcs/Bazaar.py
    /usr/lib/python3/dist-packages/pip/vcs/Subversion.py
    /usr/lib/python3/dist-packages/pip/vcs/Mercurial.py
    /usr/lib/python3/dist-packages/pip/vcs/__init__.py
    /usr/lib/python3/dist-packages/pip/vcs/git.py
    /usr/lib/python3/dist-packages/pip/cmdoptions.py
    /usr/lib/python3/dist-packages/pip/basecommand.py
    /usr/lib/python3/dist-packages/pip/commands
    /usr/lib/python3/dist-packages/pip/commands/completion.py
    /usr/lib/python3/dist-packages/pip/commands/install.py
    /usr/lib/python3/dist-packages/pip/commands/hash.py
    /usr/lib/python3/dist-packages/pip/commands/uninstall.py
    /usr/lib/python3/dist-packages/pip/commands/__init__.py
    /usr/lib/python3/dist-packages/pip/commands/list.py
    /usr/lib/python3/dist-packages/pip/commands/search.py
    /usr/lib/python3/dist-packages/pip/commands/show.py
    /usr/lib/python3/dist-packages/pip/commands/download.py
    /usr/lib/python3/dist-packages/pip/commands/wheel.py
    /usr/lib/python3/dist-packages/pip/commands/freeze.py
    /usr/lib/python3/dist-packages/pip/commands/help.py
    /usr/lib/python3/dist-packages/pip/_vendor
    /usr/lib/python3/dist-packages/pip/_vendor/__init__.py
    /usr/lib/python3/dist-packages/pip/operations
    /usr/lib/python3/dist-packages/pip/operations/__init__.py
    /usr/lib/python3/dist-packages/pip/operations/freeze.py
    /usr/lib/python3/dist-packages/pip/__init__.py
    /usr/lib/python3/dist-packages/pip/locations.py
    /usr/lib/python3/dist-packages/pip/pep425tags.py
    /usr/lib/python3/dist-packages/pip/exceptions.py
    /usr/lib/python3/dist-packages/pip/download.py
    /usr/lib/python3/dist-packages/pip/wheel.py
    /usr/share
    /usr/share/man
    /usr/share/man/man1
    /usr/share/man/man1/pip3.1.gz
    /usr/share/doc
    /usr/share/doc/python3-pip
    /usr/share/doc/python3-pip/copyright
    /usr/bin
    /usr/bin/pip3
    /usr/share/doc/python3-pip/changelog.Debian.gz
    

どうすればpip3仕事?

注:Python2のpipは正常に機能します。

==============================================

編集:

  1. import setuptools Python3では、次のエラーが表示されます。
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 11, in <module>
        from setuptools.extern.six.moves import filterfalse, map
      File "/usr/lib/python3/dist-packages/setuptools/extern/__init__.py", line 1, in <module>
        from pkg_resources.extern import VendorImporter
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2927, in <module>
        @_call_aside
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2913, in _call_aside
        f(*args, **kwargs)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in _initialize_master_working_set
        add_activation_listener(lambda dist: dist.activate())
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 956, in subscribe
        callback(dist)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2952, in <lambda>
        add_activation_listener(lambda dist: dist.activate())
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2515, in activate
        declare_namespace(pkg)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2097, in declare_namespace
        _handle_ns(packageName, path_item)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2047, in _handle_ns
        _rebuild_mod_path(path, packageName, module)
      File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2066, in _rebuild_mod_path
        orig_path.sort(key=position_in_sys_path)
    AttributeError: '_NamespacePath' object has no attribute 'sort'
  1. 次のコマンドを実行する場合sed -n '31,37p' < /usr/lib/python3/dist-packages/pip/_vendor/__init__.pyターミナルで、次の結果が得られます。

    try:
        __import__(vendored_name, globals(), locals(), level=0)
    except ImportError:
        try:
            __import__(modulename, globals(), locals(), level=0)
        except ImportError:
    

===========================================

EDIT2:

僕の python3 --versionPython 3.5.2

コードを実行して取得したインストール済みパッケージのリストls /usr/lib/python3/dist-packages

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
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
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
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
janitor
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
networkx
networkx-1.11.Egg-info
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
pexpect
pexpect-4.0.1.Egg-info
PIL
Pillow-3.1.2.Egg-info
pip
pip-8.1.1.Egg-info
pkg_resources
plotly
plotly-1.9.5.Egg-info
problem_report.py
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
pygobject-3.20.0.Egg-info
pygtkcompat
PyJWT-1.3.0.Egg-info
pylab.py
pyparsing-2.0.3.Egg-info
pyparsing.py
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
PyYAML-3.11.Egg-info
Quirks
reportlab
reportlab-3.3.0.Egg-info
requests
requests-2.9.1.Egg-info
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
six-1.10.0.Egg-info
six.py
softwareproperties
speechd
speechd_config
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
yaml
_yaml.cpython-35m-x86_64-linux-gnu.so
13
Yamila Omar

これは私のために解決しました:

curl -sS https://bootstrap.pypa.io/get-pip.py | Sudo python3

ubuntuサブシステムをいじらない特定のプロジェクトごとにvirtualenvを使用してみてください。

17
s_s.411

ありがとう@ s_s.411

次のコマンドでこの問題を解決します。

curl -sS https://bootstrap.pypa.io/get-pip.py | Sudo python3
type pip3
hash -r
pip3
4
sam

私も同じ問題を抱えており、このコマンドで解決しました。

pip uninstall pkg-resources==0.0.0
1
Razia Khan