在 Mac OS 上安装删除模块

在 Mac OS 上安装删除模块

最近,每当我尝试在 Mac OS 10.15.6 上使用 pip 安装包时,都会发生以下情况:

  • 安装成功
  • 现在模块永远无法加载,python 将始终返回ModuleNotFoundError

举个例子:

✗ pip install -U setuptools wheel
Collecting setuptools
  Using cached setuptools-49.6.0-py3-none-any.whl (803 kB)
Collecting wheel
  Using cached wheel-0.35.1-py2.py3-none-any.whl (33 kB)
Installing collected packages: setuptools, wheel
  Attempting uninstall: setuptools
    Found existing installation: setuptools 47.1.0
    Uninstalling setuptools-47.1.0:
      Successfully uninstalled setuptools-47.1.0
Successfully installed setuptools-49.6.0 wheel-0.35.1
WARNING: You are using pip version 20.1.1; however, version 20.2.2 is available.
You should consider upgrading via the '/Users/maeln/.pyenv/versions/3.8.5/bin/python3.8 -m pip install --upgrade pip' command.

Setuptools 已成功安装。但现在,执行任何操作时都需要导入 setuptools:

pip install pycairo PyGObject
Collecting pycairo
  Using cached pycairo-1.19.1.tar.gz (205 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/maeln/.pyenv/versions/3.8.5/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/8w/wqk8fyyj4k9fcq62thdz7cf00000gn/T/pip-install-cbernvg1/pycairo/setup.py'"'"'; __file__='"'"'/private/var/folders/8w/wqk8fyyj4k9fcq62thdz7cf00000gn/T/pip-install-cbernvg1/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/8w/wqk8fyyj4k9fcq62thdz7cf00000gn/T/pip-pip-egg-info-7zmrjjql
         cwd: /private/var/folders/8w/wqk8fyyj4k9fcq62thdz7cf00000gn/T/pip-install-cbernvg1/pycairo/
    Complete output (3 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ModuleNotFoundError: No module named 'setuptools'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

更糟的是!如果我尝试更新 pip:

✗ /Users/maeln/.pyenv/versions/3.8.5/bin/python3.8 -m pip install --upgrade pip
Collecting pip
  Using cached pip-20.2.2-py2.py3-none-any.whl (1.5 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.1.1
    Uninstalling pip-20.1.1:
      Successfully uninstalled pip-20.1.1
Successfully installed pip-20.2.2

✗ pip
Traceback (most recent call last):
  File "/Users/maeln/.pyenv/versions/3.8.5/bin/pip", line 5, in <module>
    from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'

我正在使用brewpython 版本(现在3.8.5)。我尝试brew doctorbrew cleanup删除已安装的所有 python 版本,仅安装 python via brew install python,最后使用pyenvnow 都无济于事。

造成这种行为的原因是什么?

相关内容