Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

公開日 : 2017-12-02

【Python MySQL】OSError: mysql_config not foundとエラーが出たので直した

このエントリーをはてなブックマークに追加

状況

PythonでMySQLの設定をしていて以下のコードを実行した。

$ sudo pip3 install flask-mysqldb

そしたら OSError: mysql_config not foundと言われてしまった。

Collecting flask-mysqldb
  Downloading Flask-MySQLdb-0.2.0.tar.gz
Requirement already satisfied (use --upgrade to upgrade): Flask>=0.10 in /usr/local/lib/python3.5/dist-packages (from flask-mysqldb)
Collecting mysqlclient (from flask-mysqldb)
  Downloading mysqlclient-1.3.12.tar.gz (89kB)
    100% |████████████████████████████████| 92kB 4.3MB/s
    Complete output from command python setup.py egg_info:
    /bin/sh: 1: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-7va_q6tq/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/tmp/pip-build-7va_q6tq/mysqlclient/setup_posix.py", line 44, in get_config
        libs = mysql_config("libs_r")
      File "/tmp/pip-build-7va_q6tq/mysqlclient/setup_posix.py", line 26, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    OSError: mysql_config not found
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-7va_q6tq/mysqlclient/
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

と言われた。

解決方法


下記Stack Overflowを参考にした。mysql_configをインストールしないといけないらしい。

mySQLdb is a python interface for mysql, but it is not mysql itself. And apparently mySQLdb needs the command 'mysql_config', so you need to install that first.
Can you confirm that you did or did not install mysql itself, by running "mysql" from the shell? That should give you a response other than "mysql: command not found".
Which linux distribution are you using? Mysql is pre-packaged for most linux distributions. For example, for debian / ubuntu, installing mysql is as easy as

なので以下のコードを実行したらOK

$ sudo apt-get install mysql-server

$ sudo apt-get install libmysqlclient-dev

もう一度

$ sudo pip3 install flask-mysqldb

を実行すればインストールできた。

スポンサーリンク