无法导入名称ContextualZipFile

时间:2018-01-01 16:13:36

标签: python

这是我尝试安装sqalchemy时获得的内容

Traceback (most recent call last):
  File "/usr/bin/easy_install", line 11, in <module>
    load_entry_point('setuptools==33.1.1', 'console_scripts', 'easy_install')()
  File "/home/j/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 572, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/home/j/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2755, in load_entry_point
    return ep.load()
  File "/home/j/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2408, in load
    return self.resolve()
  File "/home/j/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2414, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 51, in <module>
    from setuptools.archive_util import unpack_archive
  File "/usr/lib/python2.7/dist-packages/setuptools/archive_util.py", line 12, in <module>
    from pkg_resources import ContextualZipFile
ImportError: cannot import name ContextualZipFile

我尝试过安装和卸载setuptools。

我还尝试从pkg_resources import ensure_directory,ContextualZipFile&#34;更改&#34;来自pkg_resources的导入ensure_directory&#34;在我的usr / local / lib / python2.7 / dist-packages / setuptools / archive_util.py中。但是我收到了错误

Best match: MySQL-python 1.2.5
Processing MySQL-python-1.2.5.zip
Traceback (most recent call last):
  File "/usr/bin/easy_install", line 11, in <module>
    load_entry_point('setuptools==33.1.1', 'console_scripts', 'easy_install')()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 2325, in main
    **kw
  File "/usr/lib/python2.7/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 436, in run
    self.easy_install(spec, not self.no_deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 699, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 725, in install_item
    dists = self.install_eggs(spec, download, tmpdir)
  File "/usr/lib/python2.7/dist-packages/setuptools/command/easy_install.py", line 876, in install_eggs
    unpack_archive(dist_filename, tmpdir, self.unpack_progress)
  File "/usr/lib/python2.7/dist-packages/setuptools/archive_util.py", line 53, in unpack_archive
    driver(filename, extract_dir, progress_filter)
  File "/usr/lib/python2.7/dist-packages/setuptools/archive_util.py", line 102, in unpack_zipfile
    with ContextualZipFile(filename) as z:
NameError: global name 'ContextualZipFile' is not defined

我也试过直接导入pkg_resources,但它仍然无法找到ContextualZipFile。我收到错误:

NameError: global name 'ContextualZipFile' is not defined

我用 python版本= 2.7.13和 点数版本= 9.0.1

我也是在虚拟环境中做到这一点

1 个答案:

答案 0 :(得分:0)

这似乎是一个常见的错误 https://github.com/pypa/setuptools/issues/252

最简单的方法是使用替代方案,例如: yum -y install python-pip