代码之家  ›  专栏  ›  技术社区  ›  Saqib Ali

为什么pip install MySQL python==1.2.5失败并出现C编译错误?

  •  0
  • Saqib Ali  · 技术社区  · 7 年前

    我在Macbook上运行MacOS High Sierra(10.13.4版) 我在运行一个虚拟环境。

    在虚拟环境中,我正在做一个pip安装MySQL python。但是它失败了,出现了下面所示的C编译错误。

    $ pip install MySQL-python==1.2.5
    Collecting MySQL-python==1.2.5
      Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/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/saqib.ali/saqib_bnet_docs/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/q7/zl0gz8xj7ps8wswmxkqsf9khwzyc1z/T/pip-install-KM5pDI/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 /private/var/folders/q7/zl0gz8xj7ps8wswmxkqsf9khwzyc1z/T/pip-wheel-qP6Us6 --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 -I/usr/local/opt/openssl/include -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mariadb/10.3.10/include/mysql -I/usr/local/Cellar/mariadb/10.3.10/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
      In file included from _mysql.c:44:
      /usr/local/Cellar/mariadb/10.3.10/include/mysql/my_config.h:3:2: warning: This file should not be included by clients, include only <mysql.h> [-W#warnings]
      #warning This file should not be included by clients, include only <mysql.h>
       ^
    
    <WARNINGS SNIPPED FOR BREVITY>
    
    _mysql.c:2005:42: error: no member named 'reconnect' in 'struct st_mysql'
          if ( reconnect != -1 ) self->connection.reconnect = reconnect;
                                 ~~~~~~~~~~~~~~~~ ^
    16 warnings and 1 error generated.
    error: command 'cc' failed with exit status 1
    
    ----------------------------------------
    Failed building wheel for MySQL-python
    

    我删去了一些简短的警告。您可以看到完整的输出 here .

    1 回复  |  直到 7 年前
        1
  •  0
  •   Jonah    7 年前

    它看起来像是从一个不兼容的mariadb安装中获取头文件。

    你可能需要安装 mysql 和/或 mysqlclient

    有关详细信息,请参阅: Install mysqlclient for Django Python on Mac OS X Sierra