ubuntu22.04安装mysqlclient遇到 python setup.py egg_info did not run successfully.2022-8-14

ad项目场景:

背景:准备使用pytcharm来连接mysql数据库,需要先安装mysqlclinet.


问题描述

安装的过程中出现python setup.py egg_info did not run successfully.

ww@ww:~/developmeiduo/meiduo/xinhou$  pip install mysqlclient
Defaulting to user installation because normal site-packages is not writeable
Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  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 "", line 2, in 
        File "", line 34, in 
        File "/tmp/pip-install-5cvccjyi/mysqlclient_de7501e6f6254e7280597c80d28a90ee/setup.py", line 15, in 
          metadata, options = get_config()
        File "/tmp/pip-install-5cvccjyi/mysqlclient_de7501e6f6254e7280597c80d28a90ee/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/tmp/pip-install-5cvccjyi/mysqlclient_de7501e6f6254e7280597c80d28a90ee/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.


原因分析:

原因可能是安装mysql数据库的源文件缺失,尝试了网上很多种方式,用以下代码解决了我的问题。


解决方案:

sudo apt-get update
sudo apt-get install libmysqlclient-dev
pip install mysqlclient
Defaulting to user installation because normal site-packages is not writeable
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) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.1.1-cp310-cp310-linux_aarch64.whl size=105968 sha256=cc555ff00aa0072bdd7e6e6e3939f334b3dcd522fe14a8ae43edf0d31a3aa4cc
  Stored in directory: /home/ww/.cache/pip/wheels/7d/34/ba/a769c165b01646816afdf9bf792e847ef149693fee432b6b65
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1

 如上解决问题!

你可能感兴趣的:(python,开发语言,mysql)