1. 我是皮皮虾首页
  2. 编程开发
  3. 后端
  4. Python

python2使用virtualenv报错 ImportError: No module named importlib_metadata

python2使用virtualenv报错 ImportError: No module named importlib_metadata

环境

  1. centos
  2. python2.7.15

复现

[root@centos7]# virtualenv
Traceback (most recent call last):
  File "/bin/virtualenv", line 7, in <module>
    from virtualenv.__main__ import run_with_catch
  File "/usr/lib/python2.7/site-packages/virtualenv/__init__.py", line 3, in <module>
    from .run import cli_run, session_via_cli
  File "/usr/lib/python2.7/site-packages/virtualenv/run/__init__.py", line 13, in <module>
    from .plugin.activators import ActivationSelector
  File "/usr/lib/python2.7/site-packages/virtualenv/run/plugin/activators.py", line 6, in <module>
    from .base import ComponentBuilder
  File "/usr/lib/python2.7/site-packages/virtualenv/run/plugin/base.py", line 9, in <module>
    from importlib_metadata import entry_points
ImportError: No module named importlib_metadata

[root@centos7]# pip install importlib_metadata --upgrade
Collecting importlib_metadata
  Downloading https://mirrors.aliyun.com/pypi/packages/1c/7f/fe573d2225d7e0ea4bd9e8673b2c7fc0b2b2b2f86b36f8c5fe75b77e59c4/importlib_metadata-4.5.0.tar.gz
  Running setup.py (path:/tmp/pip-build-wN4JOx/importlib-metadata/setup.py) egg_info for package importlib-metadata produced metadata for project name unknown. Fix your #egg=importlib-metadata fragments.
Installing collected packages: unknown
  Found existing installation: UNKNOWN 0.0.0
    Uninstalling UNKNOWN-0.0.0:
      Successfully uninstalled UNKNOWN-0.0.0
  Running setup.py install for unknown ... done
Successfully installed unknown-0.0.0
[root@centos7 news_spider]# virtualenv

解决方法

  1. pip install –upgrade setuptools

这类错误

pip install –upgrade setuptools

Collecting setuptools
Downloading https://mirrors.aliyun.com/pypi/packages/88/fc/d17731c0cc67a5a8e385e4f47c3b0b186720e198b70f076ccb4676804a8f/setuptools-57.0.0.tar.gz (2.1MB)
100% |████████████████████████████████| 2.2MB 1.6MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File ““, line 1, in
File “setuptools/__init__.py”, line 16, in
import setuptools.version
File “setuptools/version.py”, line 1, in
import pkg_resources
File “pkg_resources/__init__.py”, line 1367
raise SyntaxError(e) from e
^
SyntaxError: invalid syntax

升级pip

pip install –upgrade pip==20.3
pip install –upgrade setuptools
pip install virtualenv
virtualenv

原创文章,作者:站长,如若转载,请注明出处:https://wsppx.cn/41/%e7%bd%91%e7%bb%9c%e5%bc%80%e5%8f%91/%e5%90%8e%e7%ab%af/python/

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注