mysqlclient-1.4.6现在无法安装(Python 3.9),而它在3.6下安装(已解决)

mysqlclient-1.4.6现在无法安装(Python 3.9),而它在3.6下安装(已解决),python,mysql,Python,Mysql,当我尝试使用pip3安装-r requirements.txt时,由于我的virtualenv(以及我的主机Python版本)是3.9而不是以前的3.6,因此mysqlclient=1.4.6的安装现在以这种方式失败: Complete output (12 lines): /bin/sh: mysql_config: command not found /bin/sh: mariadb_config: command not found /bin/sh: mysql_config: comma

当我尝试使用
pip3安装-r requirements.txt
时,由于我的virtualenv(以及我的主机Python版本)是3.9而不是以前的3.6,因此
mysqlclient=1.4.6
的安装现在以这种方式失败:

Complete output (12 lines):
/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 1, in <module>
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup.py", line 16, in <module>
    metadata, options = get_config()
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 61, in get_config
    libs = mysql_config("libs")
  File "/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py", line 29, in mysql_config
    raise EnvironmentError("%s not found" % (_mysql_config_path,))
OSError: mysql_config not found
完整输出(12行):
/bin/sh:mysql\u config:未找到命令
/bin/sh:mariadb\u配置:未找到命令
/bin/sh:mysql\u config:未找到命令
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup.py”,第16行,in
元数据,options=get_config()
文件“/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py”,第61行,在get_config中
libs=mysql_config(“libs”)
文件“/private/var/folders/78/m6t5zwl12lz2l9gjd_44x57w0000gn/T/pip-install-6d8h889b/mysqlclient_646d323b983840789a470475ee860b29/setup_posix.py”,第29行,在mysql_config中
raise环境错误(“%s未找到”)(\u mysql\u配置\u路径,)
操作错误:未找到mysql\u配置

mysql\u-config
脚本确实存在于这个系统中:
/usr/local/mysql-5.7.16-osx10.11-x86\u 64/bin/mysql\u-config
,但我不知道安装程序应该如何定位它。而且,我不知道为什么它现在失败了,而当时它没有失败。请注意。

在尝试从python脚本运行几个与mysql相关的二进制文件时,它似乎失败了。尝试设置系统的路径环境,以允许安装脚本查找与mysql相关的二进制文件

PATH="/usr/local/mysql-5.7.16-osx10.11-x86_64/bin:$PATH" pip3 install -r requirements.txt
另外,我尝试在我的Mac环境中使用相同的Python 3.9、mysqlclient 1.4.6复制安装,并且安装正常

$ python --version
Python 3.9.4

$ which mysql_config
/opt/homebrew/opt/mysql@5.7/bin/mysql_config

$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install mysqlclient==1.4.6
Collecting mysqlclient==1.4.6
  Downloading mysqlclient-1.4.6.tar.gz (85 kB)
     |████████████████████████████████| 85 kB 1.8 MB/s
Using legacy 'setup.py install' for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.6
我找到了自己的答案

在这种情况下:

export PATH=/usr/local/mysql-5.7.6-0sx10.11-x86_64/bin:$PATH

(这是我单独发现我的计算机上安装了
mysql\u config
脚本的目录–请参见上文。)问题是文件不在
$PATH
中。上述命令在当前终端会话期间将其添加到路径列表的开头


。。。然后重复上面的
pip3 install
命令,现在它就可以工作了。

Yep!结果证明这就是诀窍!(另外,在我的电脑上,我没有使用
brew
…只是MySQL的常规OS/X安装程序,它也可以正常工作。)
pip
命令找不到脚本,因为它当时不在
$PATH
中。供本线程的未来读者参考:请注意,youngminz的响应将
PATH=
命令放在命令行上,而我使用了一个单独的
export
命令。结果在功能上是相同的,在这种情况下不相关的区别是,
export
在当前会话(但不是未来会话)期间是持久的。