【问题标题】:error: command 'x86_64-linux-gnu-gcc' when installing mysqlclient错误:安装 mysqlclient 时命令“x86_64-linux-gnu-gcc”
【发布时间】:2016-01-23 17:59:39
【问题描述】:

我在 virtualenv 中安装了 django 1.8.5 并使用 python 3.4.3 使用 sqlite 时,工作显示 it works 页面

我想使用 mysql,我正在尝试使用 mysqlclient 安装

pip install mysqlclient

我收到以下消息

----------------------------------------
Failed building wheel for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient
Complete output from command /home/sasidhar/django/env/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-5lj39q67/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-da2_35zs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/sasidhar/django/env/include/site/python3.4/mysqlclient:
running install
running build
running build_py
copying MySQLdb/release.py -> build/lib.linux-x86_64-3.4/MySQLdb
running build_ext
building '_mysql' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,3,6,'final',1) -D__version__=1.3.6 -I/usr/include/mysql -I/usr/include/python3.4m -I/home/sasidhar/django/env/include/python3.4m -c _mysql.c -o build/temp.linux-x86_64-3.4/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g -DNDEBUG
_mysql.c:40:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

----------------------------------------
Command "/home/sasidhar/django/env/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip-build-5lj39q67/mysqlclient/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-da2_35zs-record/install-record.txt --single-version-externally-managed --compile --install-headers /home/sasidhar/django/env/include/site/python3.4/mysqlclient" failed with error code 1 in /tmp/pip-build-5lj39q67/mysqlclient

我确实尝试安装 error: Setup script exited with error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 中建议的库

问题仍然存在 请帮我解决这个问题
多谢你们!!

【问题讨论】:

    标签: mysql django python-3.4


    【解决方案1】:

    你需要安装python-dev:

    sudo apt-get install python-dev
    

    而且,由于您使用的是 python3:

    sudo apt-get install python3-dev
    

    这个命令应该可以帮助你。

    如果你使用的是mac os,你可以试试:

    brew update && brew rm python3 && brew install python3
    

    你需要brew已经安装,否则可以安装。它对于在 Mac OS 中获取包非常有用。 http://brew.sh/

    【讨论】:

    • @sasidhar 是的,你可以使用'sudo apt-get install python3-dev'
    • 非常感谢先生,我昨天差点尝试了 6 小时我也安装了 python-dev 但sudo apt-get install python3-dev 成功了
    • 再次感谢您,先生,您成就了我的一天 :) 现在使用 mysql db 运行 django :))
    • @sasidhar 没问题。 :) 祝你好运。 :)
    【解决方案2】:

    对于 Ubuntu,您还需要安装 build-essential

    sudo apt-get install build-essential
    

    【讨论】:

    • 这应该添加到主要答案中。它可能是 ubuntu 特定的(我不知道,但我不需要在 linux mint 上安装它来解决同样的问题)但它肯定会帮助很多人解决这个问题。
    • 我不知道它是否需要回答主要答案,但在我的情况下绝对有必要(Ubuntu 18.04)-+1
    • 这对我很有帮助,已经尝试安装 python3-dev 和其他依赖项,但后来发现这个问题
    • 这是让它最终为我工作的步骤(在 ubuntu 20.04 上)
    【解决方案3】:

    对于那些使用不同版本的人,例如 Python 3.5、3.6 或 3.7,我找到了this

    第一部分

    对于 Python 2.x 使用:

      $ sudo apt-get install python-dev
    

    对于 Python 2.7 使用:

      $ sudo apt-get install libffi-dev
    

    对于 Python 3.x 使用:

      $ sudo apt-get install python3-dev
    

    对于 Python 3.4 使用:

      $ sudo apt-get install python3.4-dev
    

    对于 Python 3.7 使用:

      $ sudo apt-get install python3.7-dev
    

    第二部分

    如果这仍然没有帮助,others 已经指出要安装

      $ sudo apt-get install build-essential
    

    最后

      $ sudo apt-get install libssl-dev
    

    但最后两个对我个人没有帮助。以防万一,希望对你有所帮助。

    【讨论】:

    • 最后两个有帮助。非常感谢
    【解决方案4】:

    对于使用python3.5的人:

    apt-get install python3.5-dev
    wget https://bootstrap.pypa.io/get-pip.py
    python3.5 get-pip.py
    pip3.5 install mysqlclient
    

    【讨论】:

      【解决方案5】:

      尝试了上述所有建议,并在其他地方找到了一些建议,但没有任何效果。最后解决方案很简单(由 ignacionf 在 GitHub 提供):

      pip install git+https://github.com/PyMySQL/mysqlclient-python.git
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-03-14
        • 2014-04-09
        • 1970-01-01
        • 2016-01-08
        相关资源
        最近更新 更多