gpt4 book ai didi

python - 问 : can't install MySQL-Python on Mac OS10. 12.3

转载 作者:太空宇宙 更新时间:2023-11-03 15:35:36 26 4
gpt4 key购买 nike

当它出现时,我试图导入 MySQLdb:

>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb

所以我开始这样做安装MySQLdb:

pip install MySQL-Python

但是,我得到了错误信息:

Collecting MySQL-Python
Using cached MySQL-python-1.2.5.zip
Installing collected packages: MySQL-Python
Running setup.py install for MySQL-Python ... error
Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/y4/qxwc6ps56fv6bc94vyp3ccjr0000gn/T/pip-build-ejJODG/MySQL-Python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /var/folders/y4/qxwc6ps56fv6bc94vyp3ccjr0000gn/T/pip-pLamdE-record/install-record.txt --single-version-externally-managed --compile:

cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. -Qunused-arguments -Qunused-arguments build/temp.macosx-10.12-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.6.27/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.12-intel-2.7/_mysql.so
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'cc' failed with exit status 1

然后,我尝试了这个:

export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib"

但这没有任何意义。然后我尝试了另一种方法:

sudo pip install mysql-connector-python

但是,它也不起作用:

Collecting mysql-connector-python
Could not find a version that satisfies the requirement mysql-connector-python (from versions: )
No matching distribution found for mysql-connector-python

由于我是 mac 和 python 的新手,所以我不知道发生了什么以及如何修复它。我的电脑上安装了python2.7.10。

最佳答案

使用PyMySQL反而。它是一个纯 Python 库,是 MySQL-Python 的替代品,并且运行良好。 MySQL-Python 的库依赖关系在各种平台上可能会带来麻烦。在您的情况下,它无法找到要链接的 open-ssl header 。

pip install pymysql

关于python - 问 : can't install MySQL-Python on Mac OS10. 12.3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42548975/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com