python 我如何安装libmysqlclient在vsc,而在一个venv时,我得到这个错误?

axr492tv  于 2024-01-05  发布在  Python
关注(0)|答案(1)|浏览(143)

我已经尝试了这里的几乎所有东西,github和其他更阴暗的网站,但venv不会在vsc中安装mysqlclient。我有一个django项目,我不能连接到mysql db。
使用MacBook Pro 2019,安装并运行MySQL。
我得到这个错误:

  1. Collecting mysql
  2. Downloading mysql-0.0.3-py3-none-any.whl (1.2 kB)
  3. Collecting mysqlclient (from mysql)
  4. Using cached mysqlclient-2.2.1.tar.gz (89 kB)
  5. Installing build dependencies ... done
  6. Getting requirements to build wheel ... error
  7. error: subprocess-exited-with-error
  8. × Getting requirements to build wheel did not run successfully.
  9. exit code: 1
  10. ╰─> [27 lines of output]
  11. Trying pkg-config --exists mysqlclient
  12. Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
  13. Trying pkg-config --exists mariadb
  14. Command 'pkg-config --exists mariadb' returned non-zero exit status 1.
  15. Trying pkg-config --exists libmariadb
  16. Command 'pkg-config --exists libmariadb' returned non-zero exit status 1.
  17. Traceback (most recent call last):
  18. File
  19. "/builddjango/capstoneVenv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
  20. main()
  21. File
  22. "/builddjango/capstoneVenv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
  23. json_out['return_val'] = hook(**hook_input['kwargs'])
  24. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  25. File
  26. "/builddjango/capstoneVenv/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
  27. return hook(config_settings)
  28. ^^^^^^^^^^^^^^^^^^^^^
  29. File "/private/var/folders/f2/kl4ptcws6p7_mn30tn5ktzk00000gn/T/pip-build-env-r64v109l/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
  30. return self._get_build_requires(config_settings, requirements=['wheel'])
  31. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  32. File "/private/var/folders/f2/kl4ptcws6p7_mn30tn5ktzk00000gn/T/pip-build-env-r64v109l/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
  33. self.run_setup()
  34. File "/private/var/folders/f2/kl4ptcws6p7_mn30tn5ktzk00000gn/T/pip-build-env-r64v109l/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
  35. exec(code, locals())
  36. File "<string>", line 155, in <module>
  37. File "<string>", line 49, in get_config_posix
  38. File "<string>", line 28, in find_package_name
  39. Exception: Can not find valid pkg-config name.
  40. Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually
  41. [end of output]
  42. note: This error originates from a subprocess, and is likely not a problem with pip.
  43. error: subprocess-exited-with-error
  44. × Getting requirements to build wheel did not run successfully.
  45. exit code: 1
  46. ╰─> See above for output.
  47. note: This error originates from a subprocess, and is likely not a problem with pip.

字符串
我尝试过的事情:

  1. MYSQLCLIENT_CFLAGS="-I/usr/local/include/mysql"
  2. MYSQLCLIENT_LDFLAGS="-L/usr/local/lib/mysql -lmysqlclient" pip3 install -U
  3. mysqlclient
  4. pip install --no-cache mysqlclient==2.2.0rc1
  5. brew install pkg-config
  6. export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"


++
有没有人能想到问题出在哪里?

i34xakig

i34xakig1#

Project description of this package on PyPi声明:
此软件包是一个“虚拟软件包”,需要安装MySQL-python(Python 2)或mysqlclient(Python 3)。实际上,这意味着“pip install mysql”将实际安装MySQL-python。请直接依赖相关软件包,而不是依赖此软件包。另请参阅:-https://pypi.python.org/pypi/MySQL-python-https://pypi.python.org/pypi/mysqlclient
因为你使用的是Python 3.12,所以你想看看https://pypi.org/project/mysqlclient/
macOS(Homebrew)安装MySQL和mysqlclient:

  1. $ # Assume you are activating Python 3 venv
  2. $ brew install mysql pkg-config
  3. $ pip install mysqlclient

字符串
如果你不想安装MySQL服务器,你可以使用mysql-client代替:

  1. $ # Assume you are activating Python 3 venv
  2. $ brew install mysql-client pkg-config
  3. $ export PKG_CONFIG_PATH="$(brew --prefix)/opt/mysql-client/lib/pkgconfig"
  4. $ pip install mysqlclient

展开查看全部

相关问题