无法为 mysqlclient 构建轮子,这是安装基于 pyproject.toml 的项目所必需的

问题描述 投票:0回答:1

我正在尝试安装我的requirements.txt文件,其中有很多软件包,除了mysqlclient之外,每个软件包都已安装。

我正在使用 Linux Mint 21.2 Python 3.10,

每当我尝试使用简单的 pip 命令或requirements.txt 安装命令运行

pip install mysqlclient
时,我都会收到以下异常:

Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [44 lines of output]
      mysql_config --version
      ['8.0.34']
      ext_options:
        library_dirs: []
        libraries: ['mysqlclient']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/usr/include/mysql']
        extra_objects: []
        define_macros: [('version_info', "(2,1,1,'final',0)"), ('__version__', '2.1.1')]
      Traceback (most recent call last):
        File "<string>", line 36, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-ld1ejldd/mysqlclient_cb96b3b879f241248051ad7b22e27ec7/setup.py", line 22, in <module>
          setuptools.setup(**metadata)
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/__init__.py", line 107, in setup
          return distutils.core.setup(**attrs)
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 172, in setup
          ok = dist.parse_command_line()
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 475, in parse_command_line
          args = self._parse_command_opts(parser, args)
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/dist.py", line 1132, in _parse_command_opts
          nargs = _Distribution._parse_command_opts(self, parser, args)
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 534, in _parse_command_opts
          cmd_class = self.get_command_class(command)
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/dist.py", line 979, in get_command_class
          self.cmdclass[command] = cmdclass = ep.load()
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/setuptools/_vendor/importlib_metadata/__init__.py", line 208, in load
          module = import_module(match.group('module'))
        File "/usr/src/Python-3.7.8/Lib/importlib/__init__.py", line 127, in import_module
          return _bootstrap._gcd_import(name[level:], package, level)
        File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
        File "<frozen importlib._bootstrap>", line 983, in _find_and_load
        File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
        File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
        File "<frozen importlib._bootstrap_external>", line 728, in exec_module
        File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/wheel/bdist_wheel.py", line 28, in <module>
          from .macosx_libfile import calculate_macosx_platform_tag
        File "/home/taimoor/Documents/Codes/sakila_flask_api/venv_env/lib/python3.7/site-packages/wheel/macosx_libfile.py", line 43, in <module>
          import ctypes
        File "/usr/src/Python-3.7.8/Lib/ctypes/__init__.py", line 7, in <module>
          from _ctypes import Union, Structure, Array
      ModuleNotFoundError: No module named '_ctypes'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

我已经尝试了stackoverflow上互联网上的所有解决方案..也将python版本更改为3.7..还降级了mysqlclient的版本...也安装了pymysql.. 什么也没有发生..

python ubuntu mysql-python
1个回答
0
投票

我遇到了完全相同的问题/错误。我最终没有使用

mysqlclient
并不得不切换到
pymysql
。所以对我来说可行的解决方案:

Pipfile(我使用的是pipenv)。如果不使用 pipelinenv,只需运行

pip install pymysql
pipenv install
(如果使用 pipelinenv)。

pymysql = "==1.1.0"

然后在顶部的主 Django 设置文件中添加以下行:

import pymysql
pymysql.install_as_MySQLdb()

感谢 Youtube 频道

[Infinetsoft solutions][https://www.youtube.com/watch?v=CNeVaTd_x0M]
的解决方案。

© www.soinside.com 2019 - 2024. All rights reserved.