大家好,所以我试图在我的本地机器上运行django连接到运行mysql的docker容器,但在尝试通过pip安装mysqlclient时仍然遇到错误。首先,我在尝试安装mysqlclient
时遇到此错误:
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
/bin/sh: mysql_config: command not found
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 44, in get_config
libs = mysql_config("libs_r")
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-mejs2ys1/mysqlclient/setup_posix.py", line 26, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
OSError: mysql_config not found
然后我继续通过brew安装mysql-connector-c
。我重新pip install mysqlclient
,现在我收到了这个错误:
Collecting mysqlclient
Using cached mysqlclient-1.3.12.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup.py", line 17, in <module>
metadata, options = get_config()
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in get_config
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 54, in <listcomp>
libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
File "/private/var/folders/8d/xdwdnphs1w5b_vtxrc67__5h0000gn/T/pip-build-8wu06grt/mysqlclient/setup_posix.py", line 12, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
在连接到在docker容器中运行的mysql时,是否有人在尝试在localmachine上运行django时遇到错误?
答案 0 :(得分:0)
当您使用macOS时,请尝试以下代码:
brew remove mysql-connector-c
brew install mysql
pip3 install mysqlclient
这对你有用。