我试图在导入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。
答案 0 :(得分:1)
请改用PyMySQL。它是一个纯粹的python库,是MySQL-Python的替代品,效果很好。 MySQL-Python的库依赖关系可能是各种平台的痛苦。在您的情况下,它找不到要链接的open-ssl标头。
pip install pymysql