big sur安装psutil

hcwei 2020年12月01日 219次浏览

问题描述:
mac最新版安装psutil模块时出现如下报错

hcwei$ pip3 install psutil
Collecting psutil
  Using cached https://files.pythonhosted.org/packages/33/e0/82d459af36bda999f82c7ea86c67610591cf5556168f48fd6509e5fa154d/psutil-5.7.3.tar.gz
Installing collected packages: psutil
  Running setup.py install for psutil ... error
    Complete output from command /Users/hcwei/PycharmProjects/pyechartsdemo/venv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/r9/qzff7kbx3jgbr_1ygnzd0z5w0000gn/T/pip-install-fabh15_a/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/r9/qzff7kbx3jgbr_1ygnzd0z5w0000gn/T/pip-record-xi_egoyt/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hcwei/PycharmProjects/pyechartsdemo/venv/include/site/python3.7/psutil:
    /usr/local/Cellar/python/10.14.1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.14.1-x86_64-3.7
    creating build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_pswindows.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_common.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/__init__.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_psosx.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_psbsd.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_psaix.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_pslinux.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_compat.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_psposix.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    copying psutil/_pssunos.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil
    creating build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_contracts.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_connections.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/runner.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_unicode.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_aix.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_memleaks.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/__main__.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    copying psutil/tests/test_testutils.py -> build/lib.macosx-10.14.1-x86_64-3.7/psutil/tests
    running build_ext
    building 'psutil._psutil_osx' extension
    creating build/temp.macosx-10.14.1-x86_64-3.7
    creating build/temp.macosx-10.14.1-x86_64-3.7/psutil
    creating build/temp.macosx-10.14.1-x86_64-3.7/psutil/arch
    creating build/temp.macosx-10.14.1-x86_64-3.7/psutil/arch/osx
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_OSX=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/hcwei/PycharmProjects/pyechartsdemo/venv/include -I/usr/local/Cellar/python/10.14.1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c psutil/_psutil_common.c -o build/temp.macosx-10.14.1-x86_64-3.7/psutil/_psutil_common.o
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_OSX=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/hcwei/PycharmProjects/pyechartsdemo/venv/include -I/usr/local/Cellar/python/10.14.1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c psutil/_psutil_posix.c -o build/temp.macosx-10.14.1-x86_64-3.7/psutil/_psutil_posix.o
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -DPSUTIL_POSIX=1 -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=573 -DPSUTIL_OSX=1 -I/usr/local/include -I/usr/local/opt/openssl/include -I/usr/local/opt/sqlite/include -I/Users/hcwei/PycharmProjects/pyechartsdemo/venv/include -I/usr/local/Cellar/python/10.14.1/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c psutil/_psutil_osx.c -o build/temp.macosx-10.14.1-x86_64-3.7/psutil/_psutil_osx.o
    psutil/_psutil_osx.c:527:20: error: implicit declaration of function 'getpagesize' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        int pagesize = getpagesize();
                       ^
    psutil/_psutil_osx.c:567:20: error: implicit declaration of function 'getpagesize' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        int pagesize = getpagesize();
                       ^
    2 errors generated.
    error: command 'clang' failed with exit status 1
    
    ----------------------------------------
Command "/Users/hcwei/PycharmProjects/pyechartsdemo/venv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/r9/qzff7kbx3jgbr_1ygnzd0z5w0000gn/T/pip-install-fabh15_a/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/r9/qzff7kbx3jgbr_1ygnzd0z5w0000gn/T/pip-record-xi_egoyt/install-record.txt --single-version-externally-managed --compile --install-headers /Users/hcwei/PycharmProjects/pyechartsdemo/venv/include/site/python3.7/psutil" failed with error code 1 in /private/var/folders/r9/qzff7kbx3jgbr_1ygnzd0z5w0000gn/T/pip-install-fabh15_a/psutil/
You are using pip version 10.0.1, however version 20.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

谷歌搜索找到如下结果
Use PAGE_SIZE macro instead of getpagesize() for macOS.

解决办法:

echo "#include <unistd.h>" > /tmp/test.h
CFLAGS="-include /tmp/test.h" pip3 install psutil