I got the below failure while trying to get MySQL-python installed on my Ubuntu/Linux Box.From the below it seem like the issue is sh: mysql_config: not found
C
this worked for me on python 3
On Ubuntu it is advised to use the distributions repository. So installing python-mysqldb should be straight forward:
sudo apt-get install python-mysqldb
If you actually want to use pip to install, which is as mentioned before not the suggested path but possible, please have a look at this previously asked question and answer: pip install mysql-python fails with EnvironmentError: mysql_config not found
Here is a very comprehensive guide by the developer: http://mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html
To get all the prerequisites for python-mysqld to install it using pip (which you will want to do if you are using virtualenv), run this:
sudo apt-get install build-essential python-dev libmysqlclient-dev
find the folder: sudo find / -name "mysql_config"
(assume it's "/opt/local/lib/mysql5/bin"
)
add it into PATH:export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH
install it again
Reread the error message. It says:
sh: mysql_config: not found
If you are on Ubuntu Natty, mysql_config
belongs to package libmysqlclient-dev
In python3 with virtualenv on a Ubuntu Bionic machine the following commands worked for me:
sudo apt install build-essential python-dev libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient
You have 2 options, as described bellow:
Distribution package like Glaslos suggested:
# sudo apt-get install python-mysqldb
In this case you can't use virtualenv no-site-packages (default option) but must use:
# virtualenv --system-site-packages myenv
Use clean virtualenv and build your own python-mysql package.
First create virtualenv:
# virtualenv myvirtualenv
# source myvirtualenv/bin/activate
Then install build dependencies:
# sudo apt-get build-dep python-mysqldb
Now you can install python-mysql
# pip install mysql-python
NOTE Ubuntu package is python-mysql*db* , python pypi package is python-mysql (without db)