在 Python 3.12.0 上构建 MySQLclient 轮时出错:clang 错误 - 无效的活动开发人员路径

问题描述 投票:0回答:1

我在尝试在 Python

mysqlclient
上安装
3.12.0
包时遇到问题。构建过程失败并出现 clang 错误。我在下面包含了相关的错误输出。

注意:我已经转向使用

PySQL
并且它正常工作。但我仍然想深入研究并解决我的项目中的以下问题。

  1. 环境详情:
  • Python版本:
    3.12.0
  • Django 版本:
    5.0.1
  1. 额外的 bash 信息:
Collecting mysqlclient
  Using cached mysqlclient-2.2.1.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [41 lines of output]
      # Options for building extension module:
        extra_compile_args: ['-I/opt/homebrew/Cellar/mysql-client/8.2.0/include/mysql', '-std=c99']
        extra_link_args: ['-L/opt/homebrew/Cellar/mysql-client/8.2.0/lib', '-lmysqlclient']
        define_macros: [('version_info', (2, 2, 1, 'final', 0)), ('__version__', '2.2.1')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-312
      creating build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/release.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/times.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      copying src/MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      creating build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      copying src/MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb/constants
      running egg_info
      writing src/mysqlclient.egg-info/PKG-INFO
      writing dependency_links to src/mysqlclient.egg-info/dependency_links.txt
      writing top-level names to src/mysqlclient.egg-info/top_level.txt
      reading manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
      reading manifest template 'MANIFEST.in'
      adding license file 'LICENSE'
      writing manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
      copying src/MySQLdb/_mysql.c -> build/lib.macosx-10.9-universal2-cpython-312/MySQLdb
      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.macosx-10.9-universal2-cpython-312
      creating build/temp.macosx-10.9-universal2-cpython-312/src
      creating build/temp.macosx-10.9-universal2-cpython-312/src/MySQLdb
      clang -fno-strict-overflow -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -O3 -Wall -arch arm64 -arch x86_64 -g "-Dversion_info=(2, 2, 1, 'final', 0)" -D__version__=2.2.1 -I/Users/fuwhis/Desktop/cloudsky/django-blog-example/env/include -I/Library/Frameworks/Python.framework/Versions/3.12/include/python3.12 -c src/MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-cpython-312/src/MySQLdb/_mysql.o -I/opt/homebrew/Cellar/mysql-client/8.2.0/include/mysql -std=c99
      xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
python mysql django macos pip
1个回答
0
投票

请参阅 PyPi 上的 macOS (Homebrew) 安装指南:

安装MySQL和mysqlclient:

$ # Assume you are activating Python 3 venv
$ brew install mysql pkg-config
$ pip install mysqlclient

如果你不想安装MySQL服务器,你可以使用mysql-client来代替:

$ # Assume you are activating Python 3 venv
$ brew install mysql-client pkg-config
$ export PKG_CONFIG_PATH="$(brew --prefix)/opt/mysql-client/lib/pkgconfig"
$ pip install mysqlclient
© www.soinside.com 2019 - 2024. All rights reserved.