macOS Sonoma下Python2.7安装matplotlib/numpy依赖报错求助
问题:Python 2.7项目安装依赖时numpy和matplotlib编译报错
环境信息
- 系统:macOS Sonoma 14.4.1 (23E224)
- Python版本:2.7.18
- pip版本:20.3.4
requirements.txt内容
astropy == 2.0.16 atomicwrites == 1.4.0 attrs == 21.2.0 backports.functools-lru-cache == 1.6.4 bidict == 0.18.4 colorama == 0.4.4 cycler == 0.10.0 funcsigs == 1.0.2 kiwisolver == 1.1.0 matplotlib == 2.2.5 mock == 1.3.0 more-itertools == 5.0.0 nose == 1.3.7 numpy == 1.16.6 pandas == 0.24.2 pbr == 1.3.0 pluggy == 0.7.1 py == 1.11.0 pyparsing == 2.4.7 python-dateutil == 2.8.2 pytz == 2021.3 scipy == 1.2.3 six == 1.16.0 tk == 0.1.0 tqdm == 4.62.3 wheel == 0.24.0 lmfit == 0.9.15
核心报错信息
ERROR: Command errored out with exit status 1: command: /Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-install-kadPSo/matplotlib/setup.py'"'"'; __file__='"'"'/private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-install-kadPSo/matplotlib/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"' '"'"', '"'"' '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-pip-egg-info-EdE3Nz cwd: /private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-install-kadPSo/matplotlib/ Complete output (3002 lines): ============================================================================ Edit setup.cfg to change the build options BUILDING MATPLOTLIB matplotlib: yes [2.2.5] python: yes [2.7.18 (default, May 18 2024, 18:29:57) [GCC Apple LLVM 15.0.0 (clang-1500.3.9.4)]] platform: yes [darwin] REQUIRED DEPENDENCIES AND EXTENSIONS numpy: yes [not found. pip may install it below.] install_requires: yes [handled by setuptools] libagg: yes [pkg-config information for 'libagg' could not be found. Using local copy.] freetype: yes [version 2.13.2] png: yes [version 1.6.43] qhull: yes [pkg-config information for 'libqhull' could not be found. Using local copy.] OPTIONAL SUBPACKAGES sample_data: yes [installing] toolkits: yes [installing] tests: no [skipping due to configuration] toolkits_tests: no [skipping due to configuration] OPTIONAL BACKEND EXTENSIONS macosx: yes [installing, darwin] qt5agg: no [PySide2 not found; PyQt5 not found] qt4agg: no [PySide not found; PyQt4 not found] gtk3agg: no [Requires pygobject to be installed.] DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality. ERROR: Command errored out with exit status 1: command: /Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-wheel-3XAIjW/numpy/setup.py'"'"'; __file__='"'"'/private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-wheel-3XAIjW/numpy/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"' '"'"', '"'"' '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-wheel-lhR0EK cwd: /private/var/folders/t_/b3qw1kjj7sx5gxc_10fdxnbr0000gq/T/pip-wheel-3XAIjW/numpy/ Complete output (2908 lines): Running from numpy source directory. blas_opt_info: blas_mkl_info: customize UnixCCompiler libraries mkl_rt not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE blis_info: customize UnixCCompiler libraries blis not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE openblas_info: customize UnixCCompiler customize UnixCCompiler libraries openblas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE atlas_3_10_blas_threads_info: Setting PTATLAS=ATLAS customize UnixCCompiler libraries tatlas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE atlas_3_10_blas_info: customize UnixCCompiler libraries satlas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE atlas_blas_threads_info: Setting PTATLAS=ATLAS customize UnixCCompiler libraries ptf77blas,ptcblas,atlas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE atlas_blas_info: customize UnixCCompiler libraries f77blas,cblas,atlas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE accelerate_info: FOUND: extra_link_args = ['-Wl,-framework', '-Wl,Accelerate'] define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)] extra_compile_args = ['-faltivec', '-I/System/Library/Frameworks/vecLib.framework/Headers'] FOUND: extra_link_args = ['-Wl,-framework', '-Wl,Accelerate'] define_macros = [('NO_ATLAS_INFO', 3), ('HAVE_CBLAS', None)] extra_compile_args = ['-faltivec', '-I/System/Library/Frameworks/vecLib.framework/Headers'] /bin/sh: svnversion: command not found non-existing path in 'numpy/distutils': 'site.cfg' lapack_opt_info: lapack_mkl_info: customize UnixCCompiler libraries mkl_rt not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE openblas_lapack_info: customize UnixCCompiler customize UnixCCompiler libraries openblas not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE openblas_clapack_info: customize UnixCCompiler customize UnixCCompiler libraries openblas,lapack not found in ['/Users/duaa.jaber/personalWorkSpace/asad/asad_dev_0.1.0/lib', '/usr/local/lib', '/usr/lib'] NOT AVAILABLE
解决步骤
1. 安装编译依赖工具
- 安装Xcode命令行工具:
xcode-select --install - 安装Subversion(解决
svnversion: command not found报错):
已安装Homebrew的话直接运行:
未安装Homebrew则先安装Homebrew,再执行上述命令。brew install svn
2. 单独安装numpy
先手动安装numpy,避免matplotlib安装时嵌套编译numpy导致的问题:
pip2 install numpy==1.16.6 --no-cache-dir
3. 安装matplotlib依赖库(可选,若仍报错则执行)
如果matplotlib安装时提示freetype或png相关错误,安装对应依赖:
brew install freetype libpng
4. 安装matplotlib
pip2 install matplotlib==2.2.5 --no-cache-dir
5. 批量安装剩余依赖
等numpy和matplotlib安装完成后,运行原命令安装剩余依赖:
pip2 install -r requirements.txt --no-cache-dir
原因说明
Python 2.7已停止维护,macOS Sonoma的编译工具链(如clang 15)与旧版本Python包兼容性较差。numpy需要从源码编译,缺少svn工具和正确的系统依赖会导致编译失败;而matplotlib依赖numpy,必须先确保numpy安装成功才能正常安装matplotlib。
内容的提问来源于stack exchange,提问作者Duaa Zahi
相关产品推荐
相关产品推荐

