brew install mysql-client
mkdir foo && cd foo
export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"
pipenv install mysqlclient
pipenv run python -c 'import MySQLdb'
退出并出现错误:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Users/foo/.local/share/virtualenvs/foo-cSg51m4-/lib/python3.12/site-packages/MySQLdb/__init__.py", line 17, in <module>
from . import _mysql
ImportError: dlopen(/Users/foo/.local/share/virtualenvs/foo-cSg51m4-/lib/python3.12/site-packages/MySQLdb/_mysql.cpython-312-darwin.so, 0x0002): Library not loaded: @rpath/libmysqlclient.24.dylib
Referenced from: <74CE3BA6-6CF0-3583-93EC-6F733D03E6C3> /Users/foo/.local/share/virtualenvs/foo-cSg51m4-/lib/python3.12/site-packages/MySQLdb/_mysql.cpython-312-darwin.so
Reason: tried: '/opt/homebrew/lib/libmysqlclient.24.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libmysqlclient.24.dylib' (no such file), '/opt/homebrew/lib/libmysqlclient.24.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/opt/homebrew/lib/libmysqlclient.24.dylib' (no such file)
和
brew install mysql-client
mkdir foo && cd foo
export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"
pipenv run pip install mysqlclient
pipenv run python -c 'import MySQLdb'
以零退出。
这是不直观的。为什么
pipenv
的工作方式不同?这是有意的行为吗?
环境:macOS 14.4 arm64 (M3) / Python 3.12 (Homebrew)
我不知道从哪里开始调查。 Python 的依赖管理对我来说太复杂了。
请这样做。
brew install mysql-client
将以下内容添加到您的 shell 配置文件(.zshrc、.bashrc 等):
export PATH="/opt/homebrew/opt/mysql-client/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/mysql-client/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql-client/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"
然后,获取文件:
source ~/.zshrc # or source ~/.bashrc
然后,
mkdir foo && cd foo
pipenv --python 3.12
pipenv install mysqlclient
pipenv run python -c 'import MySQLdb'