python安裝MySQLdb包遇到的坑:EnvironmentError: mysql_config not found

問題:

運行程序提示:ImportError: No module named MySQLdb

解決步驟:

1、安裝MySQL-python包,提示錯誤:EnvironmentError: mysql_config not found

[root@VM static]# pip2 install MySQL-python
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting MySQL-python
  Downloading http://mirrors.tencentyun.com/pypi/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 822kB/s 
    Complete output from command python setup.py egg_info:
    sh: mysql_config: 未找到命令
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-p9LTrB/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

2、MySQL-python包依賴mysql-devel包,需首先安裝mysql-devel包

yum -y install mysql-devel

3、安裝完成mysql-devel包,再次安裝MySQL-python包成功

[root@VM static]# pip2 install MySQL-python
Looking in indexes: http://mirrors.tencentyun.com/pypi/simple
Collecting MySQL-python
  Downloading http://mirrors.tencentyun.com/pypi/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
    100% |████████████████████████████████| 112kB 890kB/s 
Installing collected packages: MySQL-python
  Running setup.py install for MySQL-python ... done
Successfully installed MySQL-python-1.2.5

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章