May
May

Reputation: 193

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

I was trying to import MySQLdb while it came this:

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

so i started to install MySQLdb by doing so:

pip install MySQL-Python

however, i got the error information:

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:

and

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

then, i tried this:

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

but it did not make any sense. then i tried another method:

sudo pip install mysql-connector-python

however, it didn't work too:

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

Since I'm new to mac and python that I don't know what happend and how to fix it. I've installed python2.7.10 in my computer.

Upvotes: 1

Views: 403

Answers (1)

systemjack
systemjack

Reputation: 2985

Use PyMySQL instead. It's a pure python library, is a drop in replacement for MySQL-Python and works great. The library dependencies of MySQL-Python can be a pain on various platforms. In your case it could not find open-ssl headers to link against.

pip install pymysql

Upvotes: 1

Related Questions