为python 2.7安装MySQLdb返回错误

时间:2019-05-29 12:52:55

标签: mysql-python

pip install MySQL-python-1.2.4b4.tar.gz在Python 2.7(ubuntu 18.04)上返回此错误:

你能帮我吗?

    # pip install MySQL-python-1.2.5.zip
    Processing ./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 /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(tokeni                                                                                                 ze, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/tmpePf4                                                                                                 ITpip-wheel- --python-tag cp27:
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-2.7
      copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
      creating build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
      copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
      creating build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
      running build_ext
      building '_mysql' extension
      creating build/temp.linux-x86_64-2.7
      x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -f                                                                                                 debug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_in                                                                                                 fo=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
      _mysql.c:44:10: fatal error: my_config.h: No such file or directory
       #include "my_config.h"
                ^~~~~~~~~~~~~
      compilation terminated.
      error: command 'x86_64-linux-gnu-gcc' 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 /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(toke                                                                                                 nize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip                                                                                                 -vhjCMt-record/install-record.txt --single-version-externally-managed --compile:
        running install
        running build
        running build_py
        creating build
        creating build/lib.linux-x86_64-2.7
        copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
        creating build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/connections.py -> build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/cursors.py -> build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/release.py -> build/lib.linux-x86_64-2.7/MySQLdb
        copying MySQLdb/times.py -> build/lib.linux-x86_64-2.7/MySQLdb
        creating build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-2.7/MySQLdb/constants
        running build_ext
        building '_mysql' extension
        creating build/temp.linux-x86_64-2.7
        x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g                                                                                                  -fdebug-prefix-map=/build/python2.7-3hk45v/python2.7-2.7.15~rc1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Dversion_                                                                                                 info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o
        _mysql.c:44:10: fatal error: my_config.h: No such file or directory
         #include "my_config.h"
                  ^~~~~~~~~~~~~
        compilation terminated.
        error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

        ----------------------------------------
    Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-00mbCK-build/setup.py';f=getattr(tokenize, 'open', open)(__fi                                                                                                 le__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-vhjCMt-record/install-r                                                                                                 ecord.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-00mbCK-build/

谢谢。

1 个答案:

答案 0 :(得分:0)

如果您使用:

pip install mysqlclient == 1.4.6

相反,那么您会发现它有效。 mariadb软件包已更改了存储某些头文件的方式,并且MySQL-python pip软件包多年未更新。

我遇到了同样的问题,切换对我来说很有效。