尝试安装 psutil 导致错误

尝试安装 psutil 导致错误

因此使用以下命令:

pip install psutil
pip3 install psutil
sudo pip install psutil
python -m pip install psutil 
python3 -m pip install psutil
sudo python -m pip install psutil 
sudo python3 -m pip install psutil 

(我也尝试使用 pip3 执行上述 python 命令,但它会返回

/usr/local/opt/python@2/bin/python2.7: No module named pip3

每一个都会导致以下可怕的错误,我认为这可能与我使用的 python 版本有关,但我不知道如何修复。有人知道吗?我对 python 版本的理解有限。我已确保 python 是最新的,pip 也是最新的,但我相信我可能有不同版本的 python,我不知道如何找到正确的版本。

Collecting psutil
  Using cached https://files.pythonhosted.org/packages/1c/ca/5b8c1fe032a458c2c4bcbe509d1401dca9dda35c7fc46b36bb81c2834740/psutil-5.6.3.tar.gz
Installing collected packages: psutil
  Running setup.py install for psutil ... error
    ERROR: Complete output from command /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/qz/p48qhlk97jz017n6lg28qgx40000gn/T/pip-install-emd0g1al/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/qz/p48qhlk97jz017n6lg28qgx40000gn/T/pip-record-x4u1qnr2/install-record.txt --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_pswindows.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_common.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_psosx.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_psbsd.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_psaix.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_pslinux.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_compat.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_psposix.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    copying psutil/_pssunos.py -> build/lib.macosx-10.9-x86_64-3.7/psutil
    creating build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_contracts.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_connections.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/runner.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_unicode.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_aix.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_memory_leaks.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    copying psutil/tests/__main__.py -> build/lib.macosx-10.9-x86_64-3.7/psutil/tests
    running build_ext
    building 'psutil._psutil_osx' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/psutil
    creating build/temp.macosx-10.9-x86_64-3.7/psutil/arch
    creating build/temp.macosx-10.9-x86_64-3.7/psutil/arch/osx
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=563 -DPSUTIL_OSX=1 -I/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c psutil/_psutil_common.c -o build/temp.macosx-10.9-x86_64-3.7/psutil/_psutil_common.o
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/qz/p48qhlk97jz017n6lg28qgx40000gn/T/pip-install-emd0g1al/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/qz/p48qhlk97jz017n6lg28qgx40000gn/T/pip-record-x4u1qnr2/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/qz/p48qhlk97jz017n6lg28qgx40000gn/T/pip-install-emd0g1al/psutil/

答案1

您需要在 MacOS 上安装 xcode 开发人员工具。

xcode-select --install

这将安装您需要的开发人员工具。要切换到正确的路径,请尝试:

xcode-select --switch /Library/Developer/CommandLineTools

如果这不起作用,您可以重置 xcode:

xcode-select --reset

相关内容