天天看點

ubuntu中安裝mysqldb(python2)

1、在Linux中系統預設使用python2.7,是以需要安裝python-pip

sudo apt install python-pip
           

2、使用pip安裝mysql-python

sudo pip install mysql-python
           

注意:此刻會抛出一個錯誤,我安裝過很多機器都出現了這個錯誤。

Complete output from command python setup.py egg_info:
    sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-0PWaDX/mysql-python/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-build-0PWaDX/mysql-python/setup_posix.py", line 25, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
           

mysql_config找不到,因為這個檔案不在mysql-python裡面,在libmysqlclient-dev裡面,是以需要安裝libmysqlclient-dev。

3,再次安裝mysql-python

sudo pip install mysql-python
           

到這裡就安裝完成。安裝過很多都是可以的了。

繼續閱讀