在macOS High Sierra上安装mysql-python [英] Install mysql-python on macOS High Sierra

查看:95
本文介绍了在macOS High Sierra上安装mysql-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用命令pip install mysql-python在Python 2.7.10中安装mysql-python库.这将导致以下错误:

I am trying to install the mysql-python library in Python 2.7.10 using the command pip install mysql-python. This results in the following error:

Collecting mysql-python
  Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
  Running setup.py bdist_wheel for mysql-python ... error
  Complete output from command /Users/matt/env/identity/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-build-VuUKuW/mysql-python/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /var/folders/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/tmpmJbYFMpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.13-intel-2.7
  copying _mysql_exceptions.py -> build/lib.macosx-10.13-intel-2.7
  creating build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
  creating build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.macosx-10.13-intel-2.7
  cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.7.19/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-intel-2.7/_mysql.o
  _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:1127: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:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                  len = mysql_escape_string(out, in, size);
                      ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  _mysql.c:1168: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:1178: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:1180: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:1274: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:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                          len = strlen(buf);
                              ~ ^~~~~~~~~~~
  _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                          len = strlen(buf);
                              ~ ^~~~~~~~~~~
  _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                  len = strlen(buf);
                                      ~ ^~~~~~~~~~~
  _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                  len = strlen(buf);
                                      ~ ^~~~~~~~~~~
  _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
          if (how < 0 || how >= sizeof(row_converters)) {
              ~~~ ^ ~
  14 warnings generated.
  In file included from _mysql.c:44:
  /usr/local/Cellar/mysql/5.7.19/include/mysql/my_config.h:173:9: warning: 'SIZEOF_LONG' macro redefined [-Wmacro-redefined]
  #define SIZEOF_LONG      8
          ^
  /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:54:17: note: previous definition is here
  #        define SIZEOF_LONG             4
                  ^
  In file included from _mysql.c:44:
  /usr/local/Cellar/mysql/5.7.19/include/mysql/my_config.h:178:9: warning: 'SIZEOF_TIME_T' macro redefined [-Wmacro-redefined]
  #define SIZEOF_TIME_T    8
          ^
  /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:57:17: note: previous definition is here
  #        define SIZEOF_TIME_T           4
                  ^
  _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
          if (how < 0 || how >= sizeof(row_converters)) {
              ~~~ ^ ~
  3 warnings generated.
  cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.13-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.7.19/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-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

  ----------------------------------------
  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/matt/env/identity/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-build-VuUKuW/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/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-S7QKxD-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/matt/env/identity/include/site/python2.7/mysql-python:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-intel-2.7
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-intel-2.7
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb
    creating build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-intel-2.7/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-intel-2.7
    cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/5.7.19/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.13-intel-2.7/_mysql.o
    _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:1127: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:1129:9: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                    len = mysql_escape_string(out, in, size);
                        ~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    _mysql.c:1168: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:1178: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:1180: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:1274: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:1466:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1468:10: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                            len = strlen(buf);
                                ~ ^~~~~~~~~~~
    _mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                    len = strlen(buf);
                                        ~ ^~~~~~~~~~~
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
            if (how < 0 || how >= sizeof(row_converters)) {
                ~~~ ^ ~
    14 warnings generated.
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql/5.7.19/include/mysql/my_config.h:173:9: warning: 'SIZEOF_LONG' macro redefined [-Wmacro-redefined]
    #define SIZEOF_LONG      8
            ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:54:17: note: previous definition is here
    #        define SIZEOF_LONG             4
                    ^
    In file included from _mysql.c:44:
    /usr/local/Cellar/mysql/5.7.19/include/mysql/my_config.h:178:9: warning: 'SIZEOF_TIME_T' macro redefined [-Wmacro-redefined]
    #define SIZEOF_TIME_T    8
            ^
    /System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7/pymacconfig.h:57:17: note: previous definition is here
    #        define SIZEOF_TIME_T           4
                    ^
    _mysql.c:1589:10: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
            if (how < 0 || how >= sizeof(row_converters)) {
                ~~~ ^ ~
    3 warnings generated.
    cc -bundle -undefined dynamic_lookup -arch x86_64 -arch i386 -Wl,-F. build/temp.macosx-10.13-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql/5.7.19/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-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

    ----------------------------------------
Command "/Users/matt/env/identity/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-build-VuUKuW/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/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-S7QKxD-record/install-record.txt --single-version-externally-managed --compile --install-headers /Users/matt/env/identity/include/site/python2.7/mysql-python" failed with error code 1 in /private/var/folders/jd/57tcbb295t13k0t10kvrqrxh0000gn/T/pip-build-VuUKuW/mysql-python/

我已经在StackOverflow中搜索了此问题,并已经尝试了各种修复程序.

I have searched StackOverflow for this issue and have tried various fixes already.

xcode-select --install提供以下信息:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

此处的答案建议尝试使用以下代码:

An answer here suggested trying this code:

brew uninstall mysql
brew install mysql-connector-c
pip install mysql-python
brew unlink mysql-connector-c
brew install mysql

我已经运行了此命令,并且错误消息未更改.运行brew list表示已安装mysqlmysql-connector-copenssl.

I have run this and the error message did not change. Running brew list shows that mysql, mysql-connector-c and openssl are installed.

请注意,我正在使用macOS High Sierra beta版,这可能就是为什么其他各种修复程序无法正常工作的原因.

Please note that I am on the macOS High Sierra beta, which may be why various other fixes are not working.

推荐答案

尝试了许多其他解决方案,包括卸载,重新安装,使用pip,brew等.在调用命令时添加环境链接器变量:

Tried many other solutions involving uninstalling, re-installing, using pip, brew, etc. Add an environment linker variable as you call the command:

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip2.7 install -r requirements.txt

示例显示了一个需求文件,但可能只是您的mysql-python

Sample shows a requirements file but could be just your mysql-python

MacOSX Sierra PIP2.7

MacOSX Sierra PIP2.7

这篇关于在macOS High Sierra上安装mysql-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆