【问题标题】:Unable to install MySQL-python - failed with exit status 1无法安装 MySQL-python - 退出状态为 1 失败
【发布时间】:2021-10-28 16:18:53
【问题描述】:

我的部分项目需要 MySQL-python 包。 我正在运行 Linux Mint 20,内核 5.11 到目前为止,我的一切工作正常。只需设置我的虚拟环境,所有软件包都通过诗歌安装,除了 MySQL-python。它失败了:

fatal error: my_config.h: No such file or directory
       44 | #include "my_config.h"
          |          ^~~~~~~~~~~~~
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/matt/git/proj/test/python/.venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-f_UUOG/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-f_UUOG/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 /tmp/pip-record-XzgEIa/install-record.txt --single-version-externally-managed --compile --install-headers /home/matt/git/proj/test/python/.venv/include/site/python2.7/mysql-python Check the logs for full command output.

我尝试将my_config_h 文件夹添加到/usr/local/mysql and /home/linuxbrew/.linuxbrew/Cellar/mysql/8.0.26(自动设置)。不知道如何解决这个问题。

我有 export PATH=${PATH}:/usr/local/mysql/bin 我的 bash 配置。 我尝试使用 brew 链接/取消链接 mysql
是否有很多谷歌搜索和对其他人有用的解决方案对我不起作用。

提前致谢。

编辑:解决了一堆小错误后,现在的问题是 /home/linuxbrew/.linuxbrew/bin/ld: cannot find -lzstd 这些是我相信在 usr/bin 和上述目录中的软件包。

这里是更多的错误输出:

    /home/linuxbrew/.linuxbrew/bin/ld: cannot find -lzstd
    collect2: error: ld returned 1 exit status
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1```

【问题讨论】:

  • mysqlclient pip 包是一个替代品。 pip install mysqlclient
  • 这会引发以下错误:/home/linuxbrew/.linuxbrew/bin/ld: cannot find -lzstd collect2: error: ld returned 1 exit status error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

标签: python mysql config


【解决方案1】:

通过以下命令解决了这个问题:sudo apt-get install libzstd-dev

【讨论】:

    【解决方案2】:

    如果您的系统上有 pip 包管理器,请尝试以下操作:

    pip3 install mysql-python
    

    如果 pip 不存在,请先运行这些命令

    sudo apt update
    sudo apt install python3-pip
    

    【讨论】:

    • 使用上述命令安装时出现以下错误:ERROR: No matching distribution found for mysql-pythonprint """You shouldn't be running this directly; it is used by setup.py.""" ^ SyntaxError: Missing parentheses in call to 'print'. Did you mean print("""You shouldn't be running this directly)?raise HTTPError(req.full_url, code, msg, hdrs, fp) urllib.error.HTTPError: HTTP Error 403: SSL is requiredModuleNotFoundError: No module named 'ConfigParser'
    【解决方案3】:

    使用 python 2.7 你可以使用

    mysqlclient 1.3.5

    pip install mysqlclient==1.3.5
    

    目前支持 MySQL-3.23 到 5.5 和 Python-2.7、3.3-3.4。支持 PyPy 改用例如

    但是您需要将 urentyl 更新到 python 3.8 或 3.9

    mysql-connector-python 8.0.26

    pip install mysql-connector-python
    

    【讨论】:

    • 我使用的是 python 2.7,所以上述发行版不起作用
    • 我有充分的理由使用 Python 的 putdqated 版本吗?
    • @wheedwhackerjones 我为 python 2.7 添加了一个版本
    • 在尝试安装 mysqlclient==1.3.5 时出现此错误(与原版基本相同)fatal error: my_config.h: No such file or directory 29 | #include "my_config.h" | ^~~~~~~~~~~~~ compilation terminated. error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    • 检查此解决方案stackoverflow.com/a/61355803/5193536 并尝试更新到较新的python 版本
    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 2020-03-07
    • 2017-10-05
    • 1970-01-01
    • 2012-05-01
    • 2014-09-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多