去年我花了整整两天时间试图让 python-mysql 工作在我干净安装的 Lion 上,最后绝望地放弃了。升级到山狮后,我想我会再试一次,但没有成功。可能是我对 Lion 的所有尝试都搞砸了我的设置,我唯一的希望是全新安装,但以防万一有人能救我,这里是症状。
首先,我删除了仍然存在的三个版本:
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-i386.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-i386.egg-tmp/_mysql.so
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-x86_64.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-x86_64.egg-tmp/_mysql.so
然后重新安装。一切似乎都正常,尽管有警告,并且似乎是 64 位版本:
Phoebe-Brights-iMac:.python-eggs phoebebr$ sudo pip install mysql-python
dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
Password:
Downloading/unpacking mysql-python
Downloading MySQL-python-1.2.4c1.zip (113kB): 113kB downloaded
Running setup.py egg_info for package mysql-python
Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
Extracting in /tmp/tmp7fFOxU
Now working in /tmp/tmp7fFOxU/distribute-0.6.28
Building a Distribute egg in /private/tmp/pip-build/mysql-python
/private/tmp/pip-build/mysql-python/distribute-0.6.28-py2.7.egg
Installing collected packages: mysql-python
Running setup.py install for mysql-python
building '_mysql' extension
clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,4,'rc',5) -D__version__=1.2.4c1 -I/usr/local/mysql/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.8-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
clang: warning: argument unused during compilation: '-mno-fused-madd'
In file included from _mysql.c:44:
/usr/local/mysql/include/my_config.h:330:11: warning: 'SIZEOF_SIZE_T' macro redefined
#define SIZEOF_SIZE_T SIZEOF_LONG
^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:43:17: note: previous definition is here
# define SIZEOF_SIZE_T 8
^
In file included from _mysql.c:44:
/usr/local/mysql/include/my_config.h:423:9: warning: 'HAVE_WCSCOLL' macro redefined
#define HAVE_WCSCOLL
^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pyconfig.h:891:9: note: previous definition is here
#define HAVE_WCSCOLL 1
^
_mysql.c:287:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
cmd_argc = PySequence_Size(cmd_args);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:317:12: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
groupc = PySequence_Size(groups);
~ ^~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:470:14: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
int j, n2=PySequence_Size(fun);
~~ ^~~~~~~~~~~~~~~~~~~~
_mysql.c:1105:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_real_escape_string(&(self->connection), out, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1107:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_escape_string(out, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1146:9: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
size = PyString_GET_SIZE(s);
~ ^~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/stringobject.h:92:32: note: expanded from macro 'PyString_GET_SIZE'
#define PyString_GET_SIZE(op) Py_SIZE(op)
^
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/object.h:116:56: note: expanded from macro 'Py_SIZE'
#define Py_SIZE(ob) (((PyVarObject*)(ob))->ob_size)
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
_mysql.c:1156:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_real_escape_string(&(self->connection), out+1, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1158:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
len = mysql_escape_string(out+1, in, size);
~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_mysql.c:1252:11: warning: implicit conversion loses integer precision: 'Py_ssize_t' (aka 'long') to 'int' [-Wshorten-64-to-32]
if ((n = PyObject_Length(o)) == -1) goto error;
~ ^~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/abstract.h:434:25: note: expanded from macro 'PyObject_Length'
#define PyObject_Length PyObject_Size
^
_mysql.c:1444:10: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1446:10: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1482:11: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1484:11: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' [-Wshorten-64-to-32]
len = strlen(buf);
~ ^~~~~~~~~~~
_mysql.c:1567:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (how < 0 || how >= sizeof(row_converters)) {
~~~ ^ ~
16 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.8-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lpthread -o build/lib.macosx-10.8-intel-2.7/_mysql.so -arch x86_64
Successfully installed mysql-python
Cleaning up…
但它仍然不会导入:
Phoebe-Brights-iMac:.python-eggs phoebebr$ python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
import _mysql
ImportError: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/_mysql.so
Reason: image not found
然而它试图加载的文件就在那里!
Phoebe-Brights-iMac:/ phoebebr$ cd /Library/Python/2.7/site-packages
Phoebe-Brights-iMac:site-packages phoebebr$ ls
total 792
drwxr-xr-x 4 root wheel 136 25 Oct 09:31 Django-1.4.2-py2.7.egg
drwxr-xr-x 2 root wheel 238 23 Nov 11:16 MySQL_python-1.2.4c1-py2.7.egg-info
drwxr-xr-x 3 root wheel 510 23 Nov 11:16 MySQLdb
-rw-r--r-- 1 root wheel 119 11 Oct 23:59 README
-rwxr-xr-x 1 root wheel 67240 23 Nov 11:16 _mysql.so
-rw-r--r-- 1 root wheel 2352 23 Nov 11:16 _mysql_exceptions.py
-rw-r--r-- 1 root wheel 4243 23 Nov 11:16 _mysql_exceptions.pyc
-rw-r--r-- 1 root wheel 306 23 Nov 10:37 easy-install.pth
drwxr-xr-x 4 root wheel 136 23 Nov 10:37 pip-1.2.1-py2.7.egg
-rw-r--r-- 1 root wheel 295372 22 Oct 20:21 pymongo-2.3-py2.7-macosx-10.8-intel.egg
-rw-r--r-- 1 root wheel 17994 22 Oct 20:22 sleepy.mongoose-0.1-py2.7.egg