请帮忙解决。
我的系统详细信息:MAC(M1),OS Monterey 12.3,终端zsh。
操作步骤如下:
1. 下载并安装新的Python 3.10.3 (也尝试过3.9.11) 2. 创建并激活Python虚拟环境
Last login: Fri Mar 18 09:16:39 on ttys000
/Users/luklys/.zshrc:18: command not found: Password:
luklys@Luklys-MacBook-Air ~ % cd Documents/Code\ Projects/hello_django
luklys@Luklys-MacBook-Air hello_django % python3 -m venv .myvenv
luklys@Luklys-MacBook-Air hello_django % source .myvenv/bin/activate
(.myvenv) luklys@Luklys-MacBook-Air hello_django %
- 尝试按照MAC上https://pypi.org/project/mysqlclient/的指示安装Python MySQL客户端。
(.myvenv) luklys@Luklys-MacBook-Air hello_django % brew install mysql-client
Warning: mysql-client 8.0.28 is already installed and up-to-date.
To reinstall 8.0.28, run:
brew reinstall mysql-client
(.myvenv) luklys@Luklys-MacBook-Air hello_django %
(.myvenv) luklys@Luklys-MacBook-Air hello_django % echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc
(.myvenv) luklys@Luklys-MacBook-Air hello_django % export PATH="/usr/local/opt/mysql-client/bin:$PATH"
- 错误信息
(.myvenv) luklys@Luklys-MacBook-Air hello_django % pip install mysqlclient
Collecting mysqlclient
Using cached mysqlclient-2.1.0.tar.gz (87 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: mysql_config: command not found
/bin/sh: mariadb_config: command not found
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/private/var/folders/pw/87hvnxc51gdcwf3ck25n95tw0000gn/T/pip-install-y_1qn9ke/mysqlclient_48574969a7ff4372b5ff326147c56ec6/setup.py", line 15, in <module>
metadata, options = get_config()
File "/private/var/folders/pw/87hvnxc51gdcwf3ck25n95tw0000gn/T/pip-install-y_1qn9ke/mysqlclient_48574969a7ff4372b5ff326147c56ec6/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/private/var/folders/pw/87hvnxc51gdcwf3ck25n95tw0000gn/T/pip-install-y_1qn9ke/mysqlclient_48574969a7ff4372b5ff326147c56ec6/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
/Users/Julius
目录,添加了.zshrc
和.zsh_profile
文件,直接复制并粘贴了"export PATH=${PATH}:/usr/local/mysql/bin/"到每个文件中,然后在两个文件上运行了$ source命令,一切都正常工作了!当然,我也双重检查了"/usr/local/mysql/bin/"文件夹是否存在。在此之后,我成功安装了mysqlclient。非常感谢!这个答案对我帮助很大 ^_^ - ideaguy3d