Sharon Watinsan
Sharon Watinsan

Reputation: 9850

Can't install MySQL with Python Django environment

I am trying to install MySql with python. The approach i took is explained below:

  1. Downloaded MYSQL for Python

  2. Extracted

  3. From the terminal i navigated to the folder that i extracted in the previous step

  4. typed the command sudo python setup.py build

  5. typed the command sudo python setup.py install

In step 4 i get the following error:

h: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 18, in <module>
    metadata, options = get_config()
  File "/Users/Me/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/Users/Me/Downloads/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
(django_sampleproject)Mes-MacBook-Pro:

How can i resolve this issue ? Help.

Upvotes: 2

Views: 3451

Answers (6)

Rudra
Rudra

Reputation: 364

If you are using python 3, MySQL-python won't work, there are 2 things which you can do

method 1 : try installing python-mysqldb (most of the time it would work)

sudo apt-get install python-mysqldb

if above step is not working this would definately work

method 2: install pymysql

pip install pymysql

and add these following line in manage.py

try:
   import pymysql
   pymysql.install_as_MySQLdb()
except ImportError:
   pass

Upvotes: 0

Brad Herdson
Brad Herdson

Reputation: 11

Had a similar issue trying to install on OS X Server 10.6.8. Here's what I had to do. Using:

MySQL-python 1.2.4b4 (source) MySQL-5.6.19 (binary installer) Python 2.7 (binary installer) NOTE: Installing in virtualenv...

Unzip source, open 'distribute_setup.py' and edit DEFAULT_VERSION to use the latest version of distribute tools, like so:

DEFAULT_VERSION = "0.6.49"

Save. Open 'site.cfg' file and uncomment the path to mysql_config so it looks something like (reference your own path to mysql_config):

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config

Now clean, build and install will not fail with the 'mysql_config' not found error. Hope this helps someone else trying to make use of their old xserves :-)

Upvotes: 0

Alex Parakhnevich
Alex Parakhnevich

Reputation: 5172

That should do the trick:

1) sudo apt-get build-dep python-mysqldb

2) pip install MySQL-python

Worked like a charm for me when I have received the same error you have.

Upvotes: 2

Amit kumar pathak
Amit kumar pathak

Reputation: 41

before isntalling MySQL-python install following libraries.

sudo apt-get install libmysqlclient-dev python-dev

Upvotes: 1

StvnW
StvnW

Reputation: 1834

Save yourself a lot of hassle. Use a package manager like brew to get Python, pip, and mysql (which includes mysql_config); and then virtualenv to isolate your Django and related packages from your system Python environment.

$ brew install mysql
$ pip install virtualenv
$ virtualenv foo
$ source foo/bin/activate
$ pip install django
$ pip install mysql-python

Upvotes: 4

Kyle Hannon
Kyle Hannon

Reputation: 2249

This question is a duplicate of this: mysql_config not found when installing mysqldb python interface

and is essentially the same problem as this: pip install mysql-python fails with EnvironmentError: mysql_config not found

The solution to your problem lies in installing mysql_config. First off, did you install mysql onto your system? The MySQLdb module won't work unless mysql is installed. If you have, then I think the next step is to install the libmysqlclient-dev package (usually comes with mysql).

You should be able to install either of these with brew or macports, depending on which package manager you normally use. If you don't use a package manager, check out the documentation at http://dev.mysql.com/doc/refman/5.5/en/installing.html to get started with your mySQL installation.

Upvotes: 1

Related Questions