651

I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:,

python setup.py install

I get the following error report related to the mysql_config command.

sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

Has anyone else encountered this error and if so how did you resolve it/what can I do to successfully install mysqldb?

6
  • 1
    Hi @user904542 - I've edited your question to hopefully make it a little more concise and get you some answers :) If you don't like it, or want to provide additional details, there's an edit link directly under your question which you can use to either roll back to your original, or add to the changes I've made. Commented Sep 19, 2011 at 22:36
  • 4
    I ran into the exact same problem, because i installed mysql from source. if you do too, just run something like this to make mysql_config available: sudo ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config or add /usr/local/mysql/bin/ to your path. Commented Feb 10, 2012 at 21:48
  • If you have already installed mysql, the above comment by Thi Duong Nguyen solves the problem by creating a symlink to the mysql_config file in the /usr/bin directory, which is in the path that python will search. Commented Jan 31, 2013 at 22:04
  • 3
    just do this-------------apt-get install python-mysqldb Commented Jan 10, 2017 at 12:06
  • @AlexBoschmans symlinking /usr/bin is wrong, it is usr/local/my... see Thi's answer. Commented Mar 1, 2018 at 20:53

36 Answers 36

1
2
1

I encountered the same problem, just added the path where *mysql_config* resided to the environment variable PATH and it worked for me.

Sign up to request clarification or add additional context in comments.

Comments

1

sudo apt-get build-dep python-mysqldb will install all the dependencies to build the package from PIP/easy_install

Comments

1

As actual error is

gcc ... -I/usr/include/python2.7 ...

_mysql.c:29:20: error: Python.h: No such file or directory

and If you can't install python-dev or python-devel packages, you may download archive with needed version of python sources from http://hg.python.org/ and place headers files in proper folder for include

Comments

1

In CentOS 7 instead of yum install mysql-devel do yum install mysql-community-devel

This does not require you to add the mysql repo.

1 Comment

No package mysql-community-devel available.
1

Debian 11 install libmariadb-dev-compat to provide mysql_config binary for pip install mysqlclient

Comments

-2

sudo apt-get install libmysqlclient-dev sudo apt-get install python-dev sudo apt-get install MySQL-python

NOtice you should install python-dev as well, the packages like MySQL-python are compiled from source. The pythonx.x-dev packages contain the necessary header files for linking against python. Why does installing numpy require python-dev in Kubuntu 12.04

Comments

1
2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.