无法在Lion/Mountain Lion上安装python-mysql

3

去年我花了两天时间,试图在我的干净安装的Lion上让python-mysql工作,最后失望地放弃了。升级到Mountain 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
2个回答

13

过去我在新安装时经常遇到libmysqlclient.18.dylib错误。

这通常对我有用。

sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

我刚刚不得不进行了Mountain Lion的干净安装,现在我在使用这个软件包时遇到了新问题。v1.2.4非常新。您可以尝试pip安装MySQL-python==1.2.3,以确保安全,因为我认为1.2.4仍然处于RC1版本。

编辑:

我安装了32位的MySQL。1.2.4c1确实可以工作。建议使用export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/而不是创建符号链接。


你真是个超级明星。我做了这两件事情,然后它开始工作了。耶! - PhoebeB
哎呀!这个lib18和mysql_config总是让我头疼。 - yellottyellott
我也安装了32位的,很高兴你在答案中提到了这一点。 - crunkchitis

2
我刚刚发现了另一个可能的答案,比我通常做的更好。在终端中输入export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/,看看问题是否仍然存在。您可以将其添加到您的.profile文件中以使其持久化,这样您就不需要每次都运行它了。更多信息请参考http://www.djangoapp.com/blog/2011/07/25/django-installation-on-mac-os-x-lion/

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接