1. 程式人生 > >Mac high sierra執行pip時報錯command not found和ImportError: cannot import name ContextualZipFile

Mac high sierra執行pip時報錯command not found和ImportError: cannot import name ContextualZipFile

1、找不到pip命令

li:~ S-Li$ pip
-bash: pip: command not found

2、執行sudo easy_install pip報錯

li:~ S-Li$ sudo easy_install pip
Password:
Traceback (most recent call last):
  File "/usr/bin/easy_install-2.7", line 11, in <module>
    load_entry_point('setuptools==18.5', 'console_scripts', 'easy_install')()
  File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py"
, line 480, in load_entry_point
  return get_distribution(dist).load_entry_point(group, name) File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2691, in load_entry_point   return ep.load() File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2322, in load
  return self.resolve() File "/usr/local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2328, 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 <module>
  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 <module>   from pkg_resources import ensure_directory, ContextualZipFile ImportError: cannot import name ContextualZipFile

3、解決方法:

升級pip

li:~ S-Li$ sudo python -m pip install --upgrade --force pip
Password:
The directory '/Users/S-Li/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/S-Li/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
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 24kB/s 
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-10.0.1