【问题标题】:Can't install flask-sqlalchemy mysql-python无法安装flask-sqlalchemy mysql-python
【发布时间】:2020-09-03 21:47:40
【问题描述】:

自从 2 天以来我一直在努力安装它

pip install flask-sqlalchemy mysql-python

在我的 Ubuntu 20.4 (python 3.8) 系统上。我几乎尝试过任何事情都没有成功。

  1. first attempt
  2. second attempt
  3. thirsd attempt 现在我不知道如何解决它,因为我找到的所有解决方案都不适合我。

以下是我一次又一次遇到的错误。

在我的 Ubuntu 20.4 (python 3.8) 系统上。我几乎尝试过任何事情都没有成功。

  1. first attempt
  2. second attempt
  3. thirsd attempt 现在我不知道如何解决它,因为我找到的所有解决方案都不适合我。

以下是我一次又一次遇到的错误。

ERROR: Command errored out with exit status 1:
   command: /home/.../my_venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-npyk_a_5/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-npyk_a_5/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 /tmp/pip-wheel-oivzt0kv
       cwd: /tmp/pip-install-npyk_a_5/mysql-python/
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/release.py -> build/lib.linux-x86_64-3.8/MySQLdb
  copying MySQLdb/times.py -> build/lib.linux-x86_64-3.8/MySQLdb
  creating build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
  running build_ext
  building '_mysql' extension
  creating build/temp.linux-x86_64-3.8
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/home/.../my_venv/include -I/usr/include/python3.8 -c _mysql.c -o build/temp.linux-x86_64-3.8/_mysql.o
  _mysql.c:44:10: 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: 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
    ERROR: Command errored out with exit status 1:
     command: /home/.../my_venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-npyk_a_5/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-npyk_a_5/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-owanenoz/install-record.txt --single-version-externally-managed --compile --install-headers /home/.../my_venv/include/site/python3.8/mysql-python
         cwd: /tmp/pip-install-npyk_a_5/mysql-python/
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.8
    copying _mysql_exceptions.py -> build/lib.linux-x86_64-3.8
    creating build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/converters.py -> build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/connections.py -> build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/release.py -> build/lib.linux-x86_64-3.8/MySQLdb
    copying MySQLdb/times.py -> build/lib.linux-x86_64-3.8/MySQLdb
    creating build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-3.8/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.linux-x86_64-3.8
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/home/.../my_venv/include -I/usr/include/python3.8 -c _mysql.c -o build/temp.linux-x86_64-3.8/_mysql.o
    _mysql.c:44:10: 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/.../my_venv/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-npyk_a_5/mysql-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-npyk_a_5/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-owanenoz/install-record.txt --single-version-externally-managed --compile --install-headers /home/.../my_venv/include/site/python3.8/mysql-python Check the logs for full command output.

【问题讨论】:

    标签: python mysql pip mysql-python


    【解决方案1】:

    根据您发布的错误,我猜您可能缺少某种 mysql 依赖项。

        _mysql.c:44:10: fatal error: my_config.h: No such file or directory
           44 | #include "my_config.h"
              |          ^~~~~~~~~~~~~
    

    查看 mysqlclient 的 github page 或许您可以尝试运行:

    sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
    

    根据我的经验,缺少 .h 文件通常意味着您的计算机中缺少 Python 扩展所需的开发库

    【讨论】:

    • 等一下。为什么 mysql-python 用于 python3? mysqlclient是支持较新版本的版本
    猜你喜欢
    • 2016-11-29
    • 2012-10-11
    • 1970-01-01
    • 2022-01-22
    • 2015-03-01
    • 2013-09-05
    • 2018-07-16
    相关资源
    最近更新 更多