Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing MySQL-python

Tags:

python

mysql

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 Could someone advice me on what to do?

rmicro@ubuntu:~$ pip install MySQL-python Downloading/unpacking MySQL-python   Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded   Running setup.py egg_info for package MySQL-python     sh: mysql_config: not found     Traceback (most recent call last):       File "<string>", line 14, in <module>       File "/home/rmicro/build/MySQL-python/setup.py", line 15, 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 24, in mysql_config         raise EnvironmentError("%s not found" % (mysql_config.path,))     EnvironmentError: mysql_config not found     Complete output from command python setup.py egg_info:     sh: mysql_config: not found  Traceback (most recent call last):   File "<string>", line 14, in <module>   File "/home/rmicro/build/MySQL-python/setup.py", line 15, 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 24, in mysql_config     raise EnvironmentError("%s not found" % (mysql_config.path,)) EnvironmentError: mysql_config not found  ---------------------------------------- Command python setup.py egg_info failed with error code 1 
like image 546
user618677 Avatar asked Sep 18 '11 05:09

user618677


People also ask

Does Python 3.9 support MySQL?

@RocketHazmat yes, it worked as you said :) thank you! The support for Python 3.9 will be added in the upcoming Connector/Python 8.0.

How install MySQL install?

The simplest and recommended method is to download MySQL Installer for Windows from https://dev.mysql.com/downloads/installer/ and execute it. Select mysql-installer-web-community-8.0. 23. msi if you have good internet connection, otherwise choose mysql-installer-community-8.0.


2 Answers

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 
like image 104
Glaslos Avatar answered Sep 19 '22 18:09

Glaslos


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)

like image 20
Luka Marinko Avatar answered Sep 21 '22 18:09

Luka Marinko