pip install MySQL-python 报错

pip install MySQL-python
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://mirrors.cloud.aliyuncs.com/pypi/simple/
Collecting MySQL-python
  Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
     |████████████████████████████████| 112kB 56.4MB/s
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-kfRwp2/MySQL-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-kfRwp2/MySQL-python/
WARNING: You are using pip version 19.1.1, however version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

网上看需要安装python-devel mysql-devel 等

尝试 yum install python-devel mysql-devel ,mysql-devel有依赖问题,有如下报错

---> Package libss.x86_64 0:1.42.9-16.el7 will be an update
Removing mariadb-libs.x86_64 1:5.5.64-1.el7 - u due to obsoletes from installed mysql-community-libs-5.6.45-2.el7.x86_64
base/7/x86_64/filelists_db                                                                                                  | 7.3 MB  00:00:00
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.64-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.64-1.el7 for package: 1:mariadb-devel-5.5.64-1.el7.x86_64
--> Finished Dependency Resolution
Error: Package: 1:mariadb-devel-5.5.64-1.el7.x86_64 (base)
           Requires: mariadb-libs(x86-64) = 1:5.5.64-1.el7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

网上的建议是直接去mysql官网下载对应版本的MySQL-devel

上传rpm包MySQL-devel-5.6.46-1.el7.x86_64.rpm到服务器,之后通过命令安装mysql-devel

yum install MySQL-devel-5.6.46-1.el7.x86_64.rpm -y

之后跑pip install MySQL-python 还有报错, 看了报错,好像还得需要一个MySQL-python

yum install MySQL-python -y

之后运行pip install MySQL-python成功

总结:

下次安装的时候先运行如下,试试,有报错,再查看

yum install python-devel mysql-devel zlib zlib-devel openssl-devel MySQL-python -y

pip install MySQL-python
02-05 03:04