7π
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/
330π
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
- [Django]-Django values_list vs values
- [Django]-Handling race condition in model.save()
- [Django]-Can I access constants in settings.py from templates in Django?
- [Django]-Storing an Integer Array in a Django Database
- [Django]-How to implement FirebaseDB with a Django Web Application
- [Django]-Timestamp fields in django
58π
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.
- [Django]-NumPy array is not JSON serializable
- [Django]-Has Django served an excess of 100k daily visits?
- [Django]-How to use pdb.set_trace() in a Django unittest?
23π
Try this the commands below. They work for me:
brew install mysql-connector-c
pip install MySQL-python
- [Django]-What is a "slug" in Django?
- [Django]-How to make two django projects share the same database
- [Django]-Django: How can I create a multiple select form?
19π
mysql_config
must be on the path. On Mac, do
export PATH=$PATH:/usr/local/mysql/bin/
pip install MySQL-python
- [Django]-CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true
- [Django]-Substring in a django template?
- [Django]-Alowing 'fuzzy' translations in django pages?
14π
pip install mysql-python
raised an error:
EnvironmentError: mysql_config not found
sudo apt-get install python-mysqldb
fixed the problem.
- [Django]-Django REST Framework β 405 METHOD NOT ALLOWED using SimpleRouter
- [Django]-Homepage login form Django
- [Django]-Django: remove a filter condition from a queryset
11π
How I got it working:
virtualenv -p python3.5 env/test
After sourcing my env:
pip install pymysql
pip install django
Then, I ran the startproject and inside the manage.py, I added this:
+ try:
+ import pymysql
+ pymysql.install_as_MySQLdb()
+ except:
+ pass
Also, updated this inside settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'foobar_db',
'USER': 'foobaruser',
'PASSWORD': 'foobarpwd',
}
}
I also have configparser==3.5.0
installed in my virtualenv, not sure if that was required or notβ¦
Hope it helps,
- [Django]-Suddenly when running tests I get "TypeError: 'NoneType' object is not iterable
- [Django]-Django: guidelines for speeding up template rendering performance
- [Django]-Django form: what is the best way to modify posted data before validating?
8π
The following worked perfectly for me, running Ubuntu 13.10 64-bit:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
Now, navigate to your virtualenv (such as env folder) and execute the following:
sudo ./bin/pip install mysql-python
I actually found the solution in a separate question and I am quoting it below:
If you have created the virtualenv with the βno-site-packages switch
(the default), then system-wide installed additions such as MySQLdb
are not included in the virtual environment packages.You need to install MySQLdb with the pip command installed with the
virtualenv. Either activate the virtualenv with the bin/activate
script, or use bin/pip from within the virtualenv to install the
MySQLdb library locally as well.Alternatively, create a new virtualenv with system site-packages
included by using the βsystem-site-package switch.
I think this should also work with OSX. The only problem would be getting an equivalent command for installing libmysqlclient-dev
and python-dev
as they are needed to compile
mysql-python
I guess.
Hope this helps.
- [Django]-No module named MySQLdb
- [Django]-What does on_delete do on Django models?
- [Django]-Import data from excel spreadsheet to django model
5π
This worked for Red Hat Enterprise Linux Server release 6.4
sudo yum install mysql-devel
sudo yum install python-devel
pip install mysql-python
- [Django]-How do I run tests against a Django data migration?
- [Django]-How do Django models work?
- [Django]-What is pip install -q -e . for in this Travis-CI build tutorial?
- [Django]-Filtering dropdown values in django admin
- [Django]-Django Installed Apps Location
- [Django]-DatabaseError: current transaction is aborted, commands ignored until end of transaction block?
3π
I made the upgrade to OSX Mavericks and Pycharm 3 and start to get this error, i used pip and easy install and got the error:
commandβ/usr/bin/clangβ failed with exit status 1.
So i need to update to Xcode 5 and tried again to install using pip.
pip install mysql-python
That fix all the problems.
- [Django]-In Django 1.4, do Form.has_changed() and Form.changed_data, which are undocumented, work as expected?
- [Django]-Django index page best/most common practice
- [Django]-Django admin TabularInline β is there a good way of adding a custom html column?
2π
The error raised here is in importing the python module. This can be solved by adding the python site-packages folder to the environment variable $PYTHONPATH on OS X. So we can add the following command to the .bash_profile file:
export PYTHONPATH="$PYTHONPATH:/usr/local/lib/pythonx.x/site-packages/"
*replace x.x with the python version you are using
- [Django]-Where does pip install its packages?
- [Django]-Warning: Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'
- [Django]-Detect mobile, tablet or Desktop on Django
2π
pip
did not work for me on windows 8 64 bits system.
easy_install mysql-python
works for me.
You can use easy_install
to avoid building binaries on windows if pip does not work.
- [Django]-Django β "Incorrect type. Expected pk value, received str" error
- [Django]-Django admin file upload with current model id
- [Django]-Django: sqlite for dev, mysql for prod?
2π
If you are using python3, then try this(My OS is Ubuntu 16.04):
sudo apt-get install python3-mysqldb
- [Django]-How to use pdb.set_trace() in a Django unittest?
- [Django]-Paginate relationship in Django REST Framework?
- [Django]-Django rest framework: query parameters in detail_route
1π
I had the same problem on OSX 10.6.6. But just a simple easy_install mysql-python
on terminal did not solve it as another hiccup followed:
error: command 'gcc-4.2' failed with exit status 1
.
Apparently, this issue arises after upgrading from XCode3 (which is natively shipped with OSX 10.6) to XCode4. This newer ver removes support for building ppc arch. If its the same case, try doing as follows before easy_install mysql-python
sudo bash
export ARCHFLAGS='-arch i386 -arch x86_64'
rm -r build
python setup.py build
python setup.py install
Many thanks to Ned Deily for this solution. Check here
- [Django]-Django-allauth social account connect to existing account on login
- [Django]-Filtering dropdown values in django admin
- [Django]-Why won't Django use IPython?
0π
For me the problem got solved by simply reinstalling mysql-python
pip uninstall mysql-python
pip install mysql-python
- [Django]-Convert Django Model object to dict with all of the fields intact
- [Django]-How do I do an OR filter in a Django query?
- [Django]-How to serve media files on Django production environment?
- [Django]-How to recursively query in django efficiently?
- [Django]-Django: how to do calculation inside the template html page?
- [Django]-Is there a way to filter a queryset in the django admin?
0π
I overcame the same problem by installing MySQL-python
library using pip. You can see the message displayed on my console when I first changed my database settings in settings.py and executed makemigrations command(The solution is following the below message, just see that).
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 41, in <module>
class Permission(models.Model):
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/base.py", line 139, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/utils.py", line 240, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/Cellar/python/2.7.12_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/admin/Desktop/SetUp1/vir_env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Finally I overcame this problem as follows:
(vir_env) admins-MacBook-Pro-3:src admin$ pip install MySQLdb
Collecting MySQLdb
Could not find a version that satisfies the requirement MySQLdb (from versions: )
No matching distribution found for MySQLdb
(vir_env) admins-MacBook-Pro-3:src admin$ pip install MySQL-python
Collecting MySQL-python
Downloading MySQL-python-1.2.5.zip (108kB)
100% |ββββββββββββββββββββββββββββββββ| 112kB 364kB/s
Building wheels for collected packages: MySQL-python
Running setup.py bdist_wheel for MySQL-python ... done
Stored in directory: /Users/admin/Library/Caches/pip/wheels/38/a3/89/ec87e092cfb38450fc91a62562055231deb0049a029054dc62
Successfully built MySQL-python
Installing collected packages: MySQL-python
Successfully installed MySQL-python-1.2.5
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py makemigrations
No changes detected
(vir_env) admins-MacBook-Pro-3:src admin$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: staticfiles, rest_framework, messages, crispy_forms
Apply all migrations: admin, contenttypes, sessions, auth, PyApp
Synchronizing apps without migrations:
Creating tables...
Running deferred SQL...
Installing custom SQL...
Running migrations:
Rendering model states... DONE
Applying PyApp.0001_initial... OK
Applying PyApp.0002_auto_20170310_0936... OK
Applying PyApp.0003_auto_20170310_0953... OK
Applying PyApp.0004_auto_20170310_0954... OK
Applying PyApp.0005_auto_20170311_0619... OK
Applying PyApp.0006_auto_20170311_0622... OK
Applying PyApp.0007_loraevksensor... OK
Applying PyApp.0008_auto_20170315_0752... OK
Applying PyApp.0009_auto_20170315_0753... OK
Applying PyApp.0010_auto_20170315_0806... OK
Applying PyApp.0011_auto_20170315_0814... OK
Applying PyApp.0012_auto_20170315_0820... OK
Applying PyApp.0013_auto_20170315_0822... OK
Applying PyApp.0014_auto_20170315_0907... OK
Applying PyApp.0015_auto_20170315_1041... OK
Applying PyApp.0016_auto_20170315_1355... OK
Applying PyApp.0017_auto_20170315_1401... OK
Applying PyApp.0018_auto_20170331_1348... OK
Applying PyApp.0019_auto_20170331_1349... OK
Applying PyApp.0020_auto_20170331_1350... OK
Applying PyApp.0021_auto_20170331_1458... OK
Applying PyApp.0022_delete_postoffice... OK
Applying PyApp.0023_posoffice... OK
Applying PyApp.0024_auto_20170331_1504... OK
Applying PyApp.0025_auto_20170331_1511... OK
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying sessions.0001_initial... OK
(vir_env) admins-MacBook-Pro-3:src admin$
- [Django]-How do I clone a Django model instance object and save it to the database?
- [Django]-Suppress "?next=blah" behavior in django's login_required decorator
- [Django]-What is related_name used for?
0π
Run this command
sudo pip install mysql-python;
now you can run your command.
python manage.py startapp filename;
- [Django]-How can I avoid "Using selector: EpollSelector" log message in Django?
- [Django]-Python Asyncio in Django View
- [Django]-Django Footer and header on each page with {% extends }
0π
I encountered similar situations like yours that I am using python3.7 and django 2.1 in virtualenv on mac osx.
Try to run command:
pip install mysql-python
pip install pymysql
And edit __init__.py
file in your project folder and add following:
import pymysql
pymysql.install_as_MySQLdb()
Then run: python3 manage.py runserver
or python manage.py runserver
- [Django]-Get the list of checkbox post in django views
- [Django]-Name '_' is not defined
- [Django]-Django Admin app or roll my own?