linux # centos # python # 安装MySQLdb

安装pip

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

查看版本:

[root@localhost thirdparty]# pip -V
pip 18.0 from /usr/lib/python2.7/site-packages/pip (python 2.7)

用pip进行安装MySQLdb

yum install mysql-devel
pip install MySQL-python==1.2.3

运行结果:

[root@localhost thirdparty]# pip install MySQL-python==1.2.3
Collecting MySQL-python==1.2.3
  Using cached https://files.pythonhosted.org/packages/9a/81/924d6799494cf7fb24370335c2f782088d6ac4f79e4137d4df94cea3582c/MySQL-python-1.2.3.tar.gz
Building wheels for collected packages: MySQL-python
  Running setup.py bdist_wheel for MySQL-python ... done
  Stored in directory: /root/.cache/pip/wheels/8b/3f/0f/d22d2313b8aec0707ba79e182036fc069e5dafd865b37b2bd2
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.3

删除MySQLdb

[root@localhost thirdparty]# pip uninstall MySQL-python==1.2.3
Uninstalling MySQL-python-1.2.3:
  Would remove:
    /usr/lib64/python2.7/site-packages/MySQL_python-1.2.3.dist-info/*
Proceed (y/n)? y
  Successfully uninstalled MySQL-python-1.2.3

EnvironmentError: mysql_config not found的问题

[root@localhost thirdparty]# pip install MySQL-python==1.2.3
Collecting MySQL-python==1.2.3
  Downloading https://files.pythonhosted.org/packages/9a/81/924d6799494cf7fb24370335c2f782088d6ac4f79e4137d4df94cea3582c/MySQL-python-1.2.3.tar.gz (70kB)
    100% |████████████████████████████████| 71kB 429kB/s 
    Complete output from command python setup.py egg_info:
    sh: mysql_config: command not found
    Traceback (most recent call last):
      File "", line 1, in 
      File "/tmp/pip-install-wgfCsb/MySQL-python/setup.py", line 15, in 
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-wgfCsb/MySQL-python/

解决方法:

yum install mysql-devel

References:

https://www.liquidweb.com/kb/how-to-install-pip-on-centos-7/
https://pypi.org/project/MySQL-python/1.2.3/#files
https://blog.csdn.net/lengyuewusheng99/article/details/76984927
https://techglimpse.com/no-module-named-mysqldb-solution/

你可能感兴趣的:(linux # centos # python # 安装MySQLdb)