最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】Mac中Python2的easy_install的问题:ImportError cannot import name ContextualZipFile

Mac crifan 5423浏览 0评论

折腾:

【已解决】Mac中把Python3的pip重新换成Python2的pip

期间,去试试easy_install,结果有问题:

<code>➜  robotDemo which easy_install
/usr/bin/easy_install
➜  robotDemo easy_install --version
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in &lt;module&gt;
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in &lt;module&gt;
    from setuptools.archive_util import unpack_archive
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in &lt;module&gt;
    from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile
➜  robotDemo easy_install --help
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in &lt;module&gt;
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in &lt;module&gt;
    from setuptools.archive_util import unpack_archive
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in &lt;module&gt;
    from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile
➜  robotDemo easy_install-2.7
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in &lt;module&gt;
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 480, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2693, in load_entry_point
    return ep.load()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2324, in load
    return self.resolve()
  File "/Users/crifan/Library/Python/2.7/lib/python/site-packages/pkg_resources/__init__.py", line 2330, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/command/easy_install.py", line 46, in &lt;module&gt;
    from setuptools.archive_util import unpack_archive
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/setuptools/archive_util.py", line 15, in &lt;module&gt;
    from pkg_resources import ensure_directory, ContextualZipFile
ImportError: cannot import name ContextualZipFile
➜  robotDemo
</code>

3的没问题:

<code>➜  robotDemo easy_install-3.6
error: No urls, filenames, or requirements specified (see --help)
➜  robotDemo easy_install-3.6 --help

Global options:
  --verbose (-v)  run verbosely (default)
  --quiet (-q)    run quietly (turns verbosity off)
  --dry-run (-n)  don't actually do anything
  --help (-h)     show detailed help message
  --no-user-cfg   ignore pydistutils.cfg in your home directory

Options for 'easy_install' command:
  --prefix                   installation prefix
  --zip-ok (-z)              install package as a zipfile
  --multi-version (-m)       make apps have to require() a version
  --upgrade (-U)             force upgrade (searches PyPI for latest versions)
  --install-dir (-d)         install package to DIR
  --script-dir (-s)          install scripts to DIR
  --exclude-scripts (-x)     Don't install scripts
  --always-copy (-a)         Copy all needed packages to install dir
  --index-url (-i)           base URL of Python Package Index
  --find-links (-f)          additional URL(s) to search for packages
  --build-directory (-b)     download/extract/build in DIR; keep the results
  --optimize (-O)            also compile with optimization: -O1 for "python -
                             O", -O2 for "python -OO", and -O0 to disable
                             [default: -O0]
  --record                   filename in which to record list of installed
                             files
  --always-unzip (-Z)        don't install as a zipfile, no matter what
  --site-dirs (-S)           list of directories where .pth files work
  --editable (-e)            Install specified packages in editable form
  --no-deps (-N)             don't install dependencies
  --allow-hosts (-H)         pattern(s) that hostnames must match
  --local-snapshots-ok (-l)  allow building eggs from local checkouts
  --version                  print version information and exit
  --no-find-links            Don't load find-links defined in packages being
                             installed
  --user                     install in user site-package
                             '/Users/crifan/Library/Python/3.6/lib/python/site
                             -packages'

usage: easy_install-3.6 [options] requirement_or_url ...
   or: easy_install-3.6 --help

➜  robotDemo
</code>

然后发现:

<code>➜  robotDemo brew install easy_install
Error: No available formula with the name "easy_install"
==&gt; Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==&gt; Searching for similarly named formulae...
==&gt; Searching local taps...
Error: No similarly named formulae found.
==&gt; Searching taps...
==&gt; Searching taps on GitHub...
Error: No formulae found in taps.
</code>

mac easy_install ImportError cannot import name ContextualZipFile

ImportError (ContextualZipFile) on setuptools 8.0.2 · Issue #299 · pypa/setuptools

Import error on ContextualZipFile inside pkg_resources.py · Issue #252 · pypa/setuptools

pip – Upgrading setuptools on Mountain Lion following Python upgrade – Stack Overflow

Installation — pip 10.0.1 documentation

Installation — pip 10.0.1 documentation

ImportError: cannot import name ContextualVersionConflict – SiCKRAGE Forums

安装Caffe的Python wrapper时出现问题的解决方法 – CSDN博客

mac 安装 tensorflow – 前端印象

还是去试试,估计是没关系的python3的pip:

<code>➜  robotDemo python3 -m pip install -U --force-reinstall pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 3.2MB/s
Installing collected packages: pip
  Found existing installation: pip 10.0.0
    Uninstalling pip-10.0.0:
      Successfully uninstalled pip-10.0.0
Successfully installed pip-10.0.1
</code>

再去,问题依旧:

<code>➜  robotDemo python -m pip install -U --force-reinstall pip
/usr/bin/python: No module named pip
</code>

按照官方的去,结果出错:

<code>➜  robotDemo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1603k  100 1603k    0     0   592k      0  0:00:02  0:00:02 --:--:--  592k
➜  robotDemo python get-pip.py
Collecting pip
  Using cached https://files.pythonhosted.org/packages/0f/74/ecd13431bcc456ed390b44c8a6e917c1820365cbebcb6a8974d1cd045ab4/pip-10.0.1-py2.py3-none-any.whl
Collecting wheel
  Downloading https://files.pythonhosted.org/packages/1b/d2/22cde5ea9af055f81814f9f2545f5ed8a053eb749c08d186b369959189a8/wheel-0.31.0-py2.py3-none-any.whl (41kB)
    100% |████████████████████████████████| 51kB 135kB/s
pipenv 11.10.0 requires certifi, which is not installed.
pipenv 11.10.0 requires requests[security], which is not installed.
pipenv 11.10.0 requires virtualenv, which is not installed.
matplotlib 1.3.1 requires nose, which is not installed.
matplotlib 1.3.1 requires tornado, which is not installed.
Installing collected packages: pip, wheel
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/pip-10.0.1.dist-info'
Consider using the `--user` option or check the permissions.
</code>

搜:

Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: /Library/Python/2.7/site-packages/pip-10.0.1.dist-info

<code>➜  bin /Users/crifan/Library/Python/2.7/bin/easy_install --version
zsh: /Users/crifan/Library/Python/2.7/bin/easy_install: bad interpreter: /usr/local/opt/python/bin/python2.7: no such file or directory
➜  bin where easy_install
/usr/bin/easy_install
➜  bin ll /usr/bin/easy_install*
-rwxr-xr-x  2 root  wheel   925B  7 16  2017 /usr/bin/easy_install
-rwxr-xr-x  1 root  wheel   458B  7 16  2017 /usr/bin/easy_install-2.7
➜  bin cat /usr/bin/easy_install
#!/usr/bin/python

import sys, os
import glob, re

partA = """\
python version %d.%d.%d can't run %s.  Try the alternative(s):

"""
partB = """
Run "man python" for more information about multiple version support in
Mac OS X.
"""

sys.stderr.write(partA % (sys.version_info[:3] + (sys.argv[0],)))

dir, base = os.path.split(sys.argv[0])
specialcase = (base == 'python-config')
if specialcase:
    pat = "python*-config"
else:
    pat = base + '*'
g = glob.glob(os.path.join(dir, pat))
# match a single digit, dot and possibly multiple digits, because we might
# have 2to32.6, where the program is 2to3 and the version is 2.6.
vpat = re.compile("\d\.\d+")
n = 0
for i in g:
    vers = vpat.search(i)
    if vers is None:
    continue
    sys.stderr.write("%s (uses python %s)\n" % (i, i[vers.start():vers.end()]))
    n = 1
if n == 0:
    sys.stderr.write("(Error: no alternatives found)\n")

sys.stderr.write(partB)
sys.exit(1)
➜  bin
</code>

mac easy_install reinstall

macos – Why is Python easy_install not working on my Mac? – Stack Overflow

发现有3.6的版本,还是去删除吧:

<code>➜  robotDemo /usr/local/bin/easy_install*
error: No urls, filenames, or requirements specified (see --help)
➜  robotDemo ll /usr/local/bin/easy_install*
lrwxr-xr-x  1 crifan  admin    45B  4 17 10:52 /usr/local/bin/easy_install-3.6 -&gt; ../Cellar/python/3.6.4_4/bin/easy_install-3.6
➜  robotDemo /usr/local/bin/easy_install-3.6 --version
setuptools 38.5.2 from /usr/local/lib/python3.6/site-packages (Python 3.6)
➜  robotDemo /usr/local/bin/Cellar/python/3.6.4_4/bin/easy_install-3.6 --version
zsh: no such file or directory: /usr/local/bin/Cellar/python/3.6.4_4/bin/easy_install-3.6
➜  robotDemo /usr/local/Cellar/python/3.6.4_4/bin/easy_install-3.6 --version
setuptools 38.5.2 from /usr/local/lib/python3.6/site-packages (Python 3.6)
</code>

暂时不去管了。

等用到了Python2的easy_install再说。

转载请注明:在路上 » 【未解决】Mac中Python2的easy_install的问题:ImportError cannot import name ContextualZipFile

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.173 seconds, using 22.10MB memory