0%

Mac安装MySqldb和pylibmc时遇到的问题

今天在 Mac 上安装 MySqldb 和 pylibmc 的时候遇到两个问题,在这里记录一下。

安装 MySqldb 时,报:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Failed building wheel for MySQL-python
Running setup.py clean for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python ... error
Complete output from command /Users/jiapan/PycharmProjects/hodoor/venv/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/9j/c68zmjy53fq4t0j5y82wphr40000gn/T/pip-build-HrfNXN/MySQL-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/9j/c68zmjy53fq4t0j5y82wphr40000gn/T/pip-DdwCnb-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/jiapan/PycharmProjects/hodoor/venv/bin/../include/site/python2.7/MySQL-python:
running install
running build
running build_py
creating build
creating build/lib.macosx-10.11-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.macosx-10.11-x86_64-2.7
creating build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb
creating build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.11-x86_64-2.7/MySQLdb/constants
running build_ext
building '_mysql' extension
creating build/temp.macosx-10.11-x86_64-2.7
clang -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.7.12/include/mysql -I/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.11-x86_64-2.7/_mysql.o -fno-omit-frame-pointer
_mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (how < 0 || how >= sizeof(row_converters)) {
~~~ ^ ~
1 warning generated.
clang -bundle -undefined dynamic_lookup build/temp.macosx-10.11-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.7.12/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.11-x86_64-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 'clang' failed with exit status 1

产生原因,升级了Xcode,但是Xcode还没有启动过,里边的一些插件还没有升级。

解决方法,启动Xcode,让Xcode完成升级。

然后执行 xcode-select --install 等待完成后即可。

UPDATE AT: 2018-05-02

今天解决时问题时,上边的方法也不起作用了,stackoverflow 找到了一个方法:

sudo env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install MySQL-python

第二个问题是再安装 pylibmc 的时候报

1
2
3
4
5
6
7
8
9
./_pylibmcmodule.h:42:10: fatal error: 'libmemcached/memcached.h' file not found

#include <libmemcached/memcached.h>

^

1 error generated.

error: command 'clang' failed with exit status 1

产生原因,Mac 使用 brew 安装的 memcached 的路径和 pylibmc 认为的默认路径不一致,所以需要指定一下路径。

1
2
3
4
5
$ which memcached
/usr/local/bin/memcached

$ export LIBMEMCACHED=/usr/local
$ pip install pylibmc