安装mysqlclient报错
最近天天跟 环境作斗争,各种尝试开源的包,想找到最优解决方案,必须各种尝试装配环境
装个mysqlclient都要报错
$ pip install mysqlclient
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting mysqlclient
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/mysqlclient-2.1.1.tar.gz (88 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 88.1/88.1 kB 246.0 kB/s eta 0:00:00
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [16 lines of output]
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-1y_dnjl9/mysqlclient_3fa222c7e65143729d6121035d233910/setup.py", line 15, in <module>
metadata, options = get_config()
File "/tmp/pip-install-1y_dnjl9/mysqlclient_3fa222c7e65143729d6121035d233910/setup_posix.py", line 70, in get_config
libs = mysql_config("libs")
File "/tmp/pip-install-1y_dnjl9/mysqlclient_3fa222c7e65143729d6121035d233910/setup_posix.py", line 31, in mysql_config
raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
mysql_config --version
mariadb_config --version
mysql_config --libs
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
百度了下,少安装了sudo apt-get install libmysqlclient-dev
执行该命令安装。
然后再试一下pip install mysqlclient
还是报错
$ pip install mysqlclient
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting mysqlclient
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/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
╰─> [20 lines of output]
mysql_config --version
['8.0.32']
mysql_config --libs
['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lzstd', '-lssl', '-lcrypto', '-lresolv', '-lm']
mysql_config --cflags
['-I/usr/include/mysql']
ext_options:
library_dirs: ['/usr/lib/x86_64-linux-gnu']
libraries: ['mysqlclient', 'resolv', 'm']
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')]
running bdist_wheel
running build
running build_py
running build_ext
building 'MySQLdb._mysql' extension
error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory
[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
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
error: subprocess-exited-with-error
× Running setup.py install for mysqlclient did not run successfully.
│ exit code: 1
╰─> [22 lines of output]
mysql_config --version
['8.0.32']
mysql_config --libs
['-L/usr/lib/x86_64-linux-gnu', '-lmysqlclient', '-lzstd', '-lssl', '-lcrypto', '-lresolv', '-lm']
mysql_config --cflags
['-I/usr/include/mysql']
ext_options:
library_dirs: ['/usr/lib/x86_64-linux-gnu']
libraries: ['mysqlclient', 'resolv', 'm']
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')]
running install
/home/brooks/.virtualenvs/stock_web/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
running build_ext
building 'MySQLdb._mysql' extension
error: command 'x86_64-linux-gnu-gcc' failed: No such file or directory
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> mysqlclient
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
有百度了下,执行以下命令
sudo apt-get install python3-dev
sudo apt-get install gcc
终于安装成功
$ pip install mysqlclient
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting mysqlclient
Using cached https://pypi.tuna.tsinghua.edu.cn/packages/50/5f/eac919b88b9df39bbe4a855f136d58f80d191cfea34a3dcf96bf5d8ace0a/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) ... done
Created wheel for mysqlclient: filename=mysqlclient-2.1.1-cp310-cp310-linux_x86_64.whl size=104310 sha256=a272b0fc9a3ead0b2167faa774129a302facc502240db16c557f935b0655aea4
Stored in directory: /home/brooks/.cache/pip/wheels/99/24/e8/9e3fe4fa6f117518b07eb0c7a7a8eff5fc4c0b04a010713f89
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1