我想使用MySQLdb。我跑的时候
pip install MySQL-python
结果是
JourneydeMacBook-Pro:~ JourneyWoo$ pip install MySQL-python
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/g9/y4rms8zx6yvjjn1m1w6w0000gn/T/pip-build-JFpAwP/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/g9/y4rms8zx6yvjjn1m1w6w0000gn/T/pip-build-JFpAwP/MySQL-python/
我认为我的点子出了问题,所以我跑了
pip install --upgrade setuptools
pip install ez_setup
pip install unroll
它们都运作良好,但是当我再试一次时
pip install MySQL-python
它仍有问题。
我没有得到可以通过Google搜索解决我的问题和答案的答案,非常感谢你,如果你可以帮我解决这个问题。
答案 0 :(得分:0)
对于Linux用户
先安装python3-dev;
laptop$sudo apt-get install python3-dev # debian / Ubuntu
laptop$sudo yum install python3-devel # Red Hat / CentOS
laptop$sudo apt-get install mysqlclient
如果您以前在虚拟环境中安装过,请卸载它,它也会删除MYSQLdb,在我看来,这是所有问题的根源。 然后重新安装;
(venv)laptop:~/Desktop/app/$ pip uninstall mysqlclient
Uninstalling mysqlclient-1.3.13:
Would remove:
/usr/local/lib/python3.7/site-packages/MySQLdb/*
/usr/local/lib/python3.7/site-packages/_mysql.cpython-37m-x86_64-linux-gnu.so
/usr/local/lib/python3.7/site-packages/_mysql_exceptions.py
/usr/local/lib/python3.7/site-packages/mysqlclient-1.3.13-py3.7.egg-info
Proceed (y/n)? y
(venv)laptop:~/Desktop/app/$ pip install mysqlclient
更多详细信息here
答案 1 :(得分:0)
sudo apt-get install python-dev default-libmysqlclient-dev#Debian / Ubuntu 运行这个解决了我的问题