Har*_*rma 4 python mysql macos pip
我一直在尝试将 mysql 集成到我的 Flask 项目中。我最近迁移到 MacOS,因此很难安装依赖项。我尝试使用 pip 下载 mysql 客户端,但出现以下错误
\n Using cached mysqlclient-2.2.0.tar.gz (89 kB)\n Installing build dependencies ... done\n Getting requirements to build wheel ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 Getting requirements to build wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [25 lines of output]\n Trying pkg-config --exists mysqlclient\n Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.\n Trying pkg-config --exists mariadb\n Command 'pkg-config --exists mariadb' returned non-zero exit status 1.\n Traceback (most recent call last):\n File "/Users/L053984/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>\n main()\n File "/Users/L053984/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main\n json_out['return_val'] = hook(**hook_input['kwargs'])\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/Users/L053984/anaconda3/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel\n return hook(config_settings)\n ^^^^^^^^^^^^^^^^^^^^^\n File "/private/var/folders/m2/4ys_q90d1530pr6h8c70xj340000gp/T/pip-build-env-0g_2cgj8/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 341, in get_requires_for_build_wheel\n return self._get_build_requires(config_settings, requirements=['wheel'])\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File "/private/var/folders/m2/4ys_q90d1530pr6h8c70xj340000gp/T/pip-build-env-0g_2cgj8/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 323, in _get_build_requires\n self.run_setup()\n File "/private/var/folders/m2/4ys_q90d1530pr6h8c70xj340000gp/T/pip-build-env-0g_2cgj8/overlay/lib/python3.11/site-packages/setuptools/build_meta.py", line 338, in run_setup\n exec(code, locals())\n File "<string>", line 154, in <module>\n File "<string>", line 48, in get_config_posix\n File "<string>", line 27, in find_package_name\n Exception: Can not find valid pkg-config name.\n Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually\n [end of output]\n \n note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: subprocess-exited-with-error\n\n\xc3\x97 Getting requirements to build wheel did not run successfully.\n\xe2\x94\x82 exit code: 1\n\xe2\x95\xb0\xe2\x94\x80> See above for output.\n\nnote: This error originates from a subprocess, and is likely not a problem with pip\nRun Code Online (Sandbox Code Playgroud)\n我安装了brew 和MacPorts,但无法解决问题。如有帮助,将不胜感激
\n小智 11
该文档帮助了我: https: //github.com/PyMySQL/mysqlclient
我按照下面的部分进行操作。
安装 MySQL 和 mysqlclient:
# Assume you are activating Python 3 venv
$ brew install mysql pkg-config
$ pip install mysqlclient
Run Code Online (Sandbox Code Playgroud)
如果你不想安装MySQL服务器,你可以使用mysql-client来代替:
# Assume you are activating Python 3 venv
$ brew install mysql-client pkg-config
$ export PKG_CONFIG_PATH="/opt/homebrew/opt/mysql-client/lib/pkgconfig"
$ pip install mysqlclient
Run Code Online (Sandbox Code Playgroud)
我使用的是 MariaDB docker 镜像,所以我不想在我的 Mac 上安装 mysql,所以我遵循了第二条指令。