How to use MySQLdb with Python and Django in OSX 10.6?
Solution 1
This issue was the result of an incomplete / incorrect installation of the MySQL for Python adapter. Specifically, I had to edit the path to the mysql_config file to point to /usr/local/mysql/bin/mysql_config - discussed in greater detail in this article: http://dakrauth.com/blog/entry/python-and-django-setup-mac-os-x-leopard/
Solution 2
I had the same error and pip install MySQL-python
solved it for me.
Alternate installs:
- If you don't have pip,
easy_install MySQL-python
should work. - If your python is managed by a packaging system, you might have to use
that system (e.g.
sudo apt-get install ...
)
Below, Soli notes that if you receive the following error:
EnvironmentError: mysql_config not found
... then you have a further system dependency issue. Solving this will vary from system to system, but for Debian-derived systems:
sudo apt-get install python-mysqldb
Solution 3
Running Ubuntu, I had to do:
sudo apt-get install python-mysqldb
Solution 4
Adding to other answers, the following helped me finish the installation mysql-python:
virtualenv, mysql-python, pip: anyone know how?
On Ubuntu...
apt-get install libmysqlclient-dev
apt-get install python-dev
pip install mysql-python
Don't forget to add 'sudo' to the beginning of commands if you don't have the proper permissions.
Solution 5
Try this the commands below. They work for me:
brew install mysql-connector-c
pip install MySQL-python
Related videos on Youtube
Joe
Updated on July 05, 2020Comments
-
Joe almost 4 years
This is a much discussed issue for OSX 10.6 users, but I haven't been able to find a solution that works. Here's my setup:
Python 2.6.1 64bit Django 1.2.1 MySQL 5.1.47 osx10.6 64bit
I create a virtualenvwrapper with --no-site-packages, then installed Django. When I activate the virtualenv and run python manage.py syncdb, I get this error:
Traceback (most recent call last): File "manage.py", line 11, in <module> execute_manager(settings) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 257, in fetch_command klass = load_command_class(app_name, subcommand) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/__init__.py", line 67, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/commands/syncdb.py", line 7, in <module> from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/core/management/sql.py", line 5, in <module> from django.contrib.contenttypes import generic File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module> from django.db import connection File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/__init__.py", line 75, in <module> connection = connections[DEFAULT_DB_ALIAS] File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 91, in __getitem__ backend = load_backend(db['ENGINE']) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/utils.py", line 32, in load_backend return import_module('.base', backend_name) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/utils/importlib.py", line 35, in import_module __import__(name) File "/Users/joerobinson/.virtualenvs/dj_tut/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 14, in <module> raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I've also installed the MySQL for Python adapter, but to no avail (maybe I installed it improperly?).
Anyone dealt with this before?
-
Joe almost 14 yearsThis issue was the result of an incomplete / incorrect installation of the MySQL for Python adapter. Specifically, I had to edit the path to the mysql_config file to point to /usr/local/mysql/bin/mysql_config - discussed in greater detail in this article: dakrauth.com/blog/entry/…
-
shadow0359 over 7 yearsjust do this----------apt-get install python-mysqldb
-
Ivan Carrasco Quiroz almost 7 years
pip install mysql
worked for me!
-
-
Tomasz Iniewicz about 13 yearsyea, i used Synaptic Package Manager to search for mysql-python and install and it worked great. Thanks.
-
Facundo Casco almost 13 yearsHe is running OS X, not Ubuntu
-
Twirrim about 12 yearsAlso that wouldn't put it in the virtualenv
-
g19fanatic over 11 yearsUnder Fedora 17:
sudo yum install MySQL-python
:) -
a coder over 11 yearserror: Can't download osdn.dl.sourceforge.net/sourceforge/mysql-python/…: 404 Not Found
-
Cerin over 11 yearsLast note is incorrect. There's no pip or system package named "python-mysqldb".
-
anders over 11 years
$ mysql_config
The program 'mysql_config' is currently not installed. You can install it by t yping:sudo apt-get install libmysqlclient-dev
-
George Stocker about 11 yearsThe last step doesn't work for Mac OS X clients, as they don't have apt-get.
-
user798719 almost 11 yearsthe key is apt-get install python-dev. No idea why I'm installing a dev version of python 2 years later, but this works as of today using python 2.7.3. Only 3 hours wasted.
-
Siwei almost 11 yearsshould add this answer to the django official document
-
andilabs over 10 years
easy_install MySQL-python
on Mac OS X Mountain Lion 10.8.4 was what I needed to get rid off:django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
-
filistea over 10 yearsI've tried this and still get the same error: 'raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb'
-
napstercake almost 10 yearsI think I'm the unique person with this error 'Command python setup.py egg_info failed with error code 1' after run 'pip install MySQL-python'
-
dobs almost 10 yearsThanks! You need to install MySQLdb with the pip command installed with the virtualenv. - Helps
-
S.. over 9 yearsremember to 'sudo service apache2 restart' for these changes to take affect
-
theblackpearl over 9 yearsThanks.
sudo ./bin/pip install mysql-python
is very helpful! -
Ryan Walton over 9 yearsThanks. This worked to fix the issue for me with heroku and cleardb:ignite on django 1.7.1.
-
LearnAWK over 8 yearsThis method solved my problem. All other suggestions before give me an error message of
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/r8/c_tscq492sn641w5vtvqcvkw0000gp/T/pip-build-JYY1du/MySQL-python
-
Paullo over 8 yearsThanks Greatly, try all stated above. None worked on OSX 10.11 expect this
-
hudolejev about 8 yearsCentOS 7, option 1:
yum install MySQL-python
; option 2 (if using virtualenv):yum install mysql-devel; venv/bin/pip install MySQL-python
. -
A Star over 7 yearsthis sorted it for me, as i believe this is the version to use for Python 3
-
Stony over 6 years@LearnAWK it doesn't work. I still get the error Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/3m/97mbsh5x2bnghhk55130bh_h0000gn/T/pip-build-FFU1vL/MySQL-python/
-
Kamaldeep singh Bhatia about 6 yearsI tried this : stackoverflow.com/questions/25459386/… but failed, this saved me.. (Y)