141๐
It looks like you donโt have the python mysql package installed, try:
pip install mysql-python
or if not using a virtual environment (on *nix hosts):
sudo pip install mysql-python
49๐
If you get errors trying to install mysqlclient with pip, you may lack the mysql dev library. Install it by running:
apt-get install libmysqlclient-dev
and try again to install mysqlclient:
pip install mysqlclient
- [Django]-In Django โ Model Inheritance โ Does it allow you to override a parent model's attribute?
- [Django]-Django REST framework post array of objects
- [Django]-Django REST framework: non-model serializer
41๐
You have to install python-mysqldb
โ Python interface to MySQL.
Try:
sudo apt-get install python-mysqldb
- [Django]-Printing Objects in Django
- [Django]-Get the latest record with filter in Django
- [Django]-How to execute a Python script from the Django shell?
14๐
My answer is similar to @Ron-E, but I got a few more errors/corrections so Iโm putting my steps below for Mac OSX on Mavericks and Python 2.7.6.
-
Install Python mysql package (if you get a success message, then ignore the below steps)
pip install mysql-python
-
When I did the above, I got the error โEnvironmentError: mysql_config not foundโ
To fix this, I did the below in terminal:export PATH=$PATH:/usr/local/mysql/bin
-
When I reran step 1, I get a new error โerror: command โccโ failed with exit status 1โ
To fix this, I did the below in terminal:export CFLAGS=-Qunused-arguments export CPPFLAGS=-Qunused-arguments
-
I reran step 1 and got the success message โSuccessfully installed mysql-pythonโ!
- [Django]-Error: could not determine PostgreSQL version from '10.3' โ Django on Heroku
- [Django]-CSS styling in Django forms
- [Django]-In Django โ Model Inheritance โ Does it allow you to override a parent model's attribute?
12๐
When I set up Django development environment for PyCharm in Mac OS X Mountain Lion with python, mysql, sequel pro application I got error same as owner of this thread.
However, my answer for them who is running python-mysqldb under Mac OS Mountain Lion x86_x64 (MySql and Python also should be same architecture) and already tried everything like pip and etc. In order fix this problem do following steps:
- Download MySql for Python from here
- Untar downloaded file. In terminal window do following: tar xvfz downloade.tar.
- cd /to untared directory
- Run sudo python setup.py install
-
If you get error something like this: โEnvironment Error: /usr/local/bin/mysql_config not foundโ then try to add path ass follows: โexport PATH=$PATH:/usr/local/mysql/binโ. But id did not helped to me and I found another solution. In the end of command execution error output which looks like this:
File โ/path_to_file/MySQL-python-1.2.4b4/setup_posix.pyโ, line 25, in mysql_config
raise EnvironmentError(โ%s not foundโ % (mysql_config.path,)) -
Open setup_posix.py with vim and go to line 25 (In your case it can be different unless if it is same version).
-
Line 25 should look like this after your editing unless your mysql have symbolic link like follows โ/usr/local/mysql/bin/โ:
f = popen("%s --%s" % ('/usr/local/mysql/bin/mysql_config', what))
-
After this I got another error as following:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Library/Python/2.7/site-packages/MySQL_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so
Reason: image not found -
Finally I did following in console:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Currently everything works fine. So I hope it will be helpful for somebody who uses Mac. ๐
- [Django]-TypeError: data.forEach is not a function
- [Django]-How to access a dictionary element in a Django template?
- [Django]-Django-tables2: How to use accessor to bring in foreign columns?
9๐
If you are using Python version 3.4 or above, you have to install
sudo apt-get install python3-dev libmysqlclient-dev
in your terminal. Then install pip install mysqlclient
on your virtual env or where you installed pip.
- [Django]-Django Admin Form for Many to many relationship
- [Django]-Celery. Decrease number of processes
- [Django]-Distributed task queues (Ex. Celery) vs crontab scripts
9๐
Iโve solved this issue in this environment:
$ pyenv --version
pyenv 1.2.9
$ python --version
Python 3.7.2
$ python -m django --version
2.1.7
./settings.py
DATABASES = {
'default': {
'NAME': 'my_db_name',
'ENGINE': 'mysql.connector.django', # 'django.db.backends.mysql'
'USER': '<user>',
'PASSWORD': '<pass>',
'HOST': 'localhost',
'PORT': 3306,
'OPTIONS': {
'autocommit': True,
},
}
}
If you use 'ENGINE': 'mysql.connector.django'
, install driver executing:
$ pip install mysql-connector-python
Successfully installed mysql-connector-python-8.0.15 protobuf-3.7.0 six-1.12.0
Note that $ pip install mysql-python
didnโt work for me.
Note that if you use 'ENGINE': 'django.db.backends.mysql'
, you should install driver executing:
$ pip install mysqlclient
Finally execute:
$ python manage.py migrate
If itโs all right, python creates all these tables id database:
auth_group
auth_group_permissions
auth_permission
auth_user
auth_user_groups
auth_user_user_permissions
django_admin_log
django_content_type
django_migrations
django_session
- [Django]-Django URLs TypeError: view must be a callable or a list/tuple in the case of include()
- [Django]-Change a Django form field to a hidden field
- [Django]-Cross domain at axios
8๐
You are missing the python mysqldb
library. Use this command (for Debian/Ubuntu) to install it:
sudo apt-get install python-mysqldb
- [Django]-"gettext()" vs "gettext_lazy()" in Django
- [Django]-How does django handle multiple memcached servers?
- [Django]-Django test app error โ Got an error creating the test database: permission denied to create database
- [Django]-Django reverse lookup of foreign keys
- [Django]-Should I be adding the Django migration files in the .gitignore file?
- [Django]-No module named MySQLdb
6๐
Download and install Mysql-python from here for windows environment. http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python.
- [Django]-How can I filter a Django query with a list of values?
- [Django]-How to pass information using an HTTP redirect (in Django)
- [Django]-How do you catch this exception?
5๐
For Ubuntu 16.04 and 18.04 or python 3 versions
sudo apt-get install python3-mysqldb
- [Django]-Inline in ModelForm
- [Django]-Pulling data to the template from an external database with django
- [Django]-Django substr / substring in templates
3๐
On Ubuntu it is advised to use the distributions repository.
sudo apt-get install python-mysqldb
- [Django]-Django โ iterate number in for loop of a template
- [Django]-"gettext()" vs "gettext_lazy()" in Django
- [Django]-UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)
- [Django]-Django โ No module named _sqlite3
- [Django]-Gunicorn autoreload on source change
- [Django]-Django model constraint for related objects
2๐
With the same error message as Will, it worked for me to install mysql first as the missing file will be added during the installation.
So after
brew install mysql
pip install mysql-python
ran without errors.
- [Django]-How to create an object for a Django model with a many to many field?
- [Django]-Django โ "no module named django.core.management"
- [Django]-How to migrate back from initial migration in Django 1.7?
2๐
This happened with me as well and I believe this has become a common error not only for Django developers but also for Flask as well, so the way I solved this issue was using brew.
brew install mysql
sudo pip install mysql-python
This way every single issue was solved and both frameworks work absolutely fine.
P.S.: For those who use macports (such as myself), this can be an issue as brew works in a different level, my advice is to use brew instead of macports
I hope I could be helpful.
- [Django]-Django "xxxxxx Object" display customization in admin action sidebar
- [Django]-Multiple annotate Sum terms yields inflated answer
- [Django]-Django: Redirect to previous page after login
2๐
I was having the same problem.The following solved my issue
Run pip install pymysql
in your shell
Then, edit the init.py
file in your project origin directory (the same as settings.py
)
and then
add:
import pymysql
pymysql.install_as_MySQLdb()
this should solve the problem.
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
- [Django]-Django: Redirect to previous page after login
- [Django]-What is a django.utils.functional.__proxy__ object and what it helps with?
2๐
I think it is the version error.
try installing this in following order:
-
sudo apt-get install python3-mysqldb
-
pip3 install mysqlclient
-
python3 manage.py makemigrations
-
python3 manage.py migrate
- [Django]-Django.db.utils.ProgrammingError: relation already exists
- [Django]-Sending an SMS to a Cellphone using Django
- [Django]-Custom django admin templates not working
1๐
I faced this similar error to when I wanted to use MySQL as the default database.
These error might be as a result of the fact that mysqlclient hasnโt been installed.
And this can be installed from the command line using;
pip install mysqlclient
(for recent versions of python)
or pip install mysql-python
(for older versions of python)
In my case, after meeting this requirement, I still had this same error and it was solved as below;
In your django project directory, select venv directory and under these directory,
select the pyvenv.cfg file and click allow on the dialog box which ask you if you want to edit this file. In this file,
include-system-site-packages
is set to false
. So change this line of code to true like this;
include-system-site-packages = true
Everything now works well
- [Django]-What's the difference between select_related and prefetch_related in Django ORM?
- [Django]-Allowing RabbitMQ-Server Connections
- [Django]-Sending images using Http Post
1๐
I was stuck in this for a very long and then I realized whatโs wrong django checks for mysqlclient if itโs not installed before django it throws this error so simple solution is
pip uninstall django
pip install mysqlclient
pip install django
- [Django]-Django: Error: You don't have permission to access that port
- [Django]-Celery : Execute task after a specific time gap
- [Django]-Pagination in Django-Rest-Framework using API-View
0๐
Just to add to other answers, if youโre using Django, it is advisable that you install mysql-python BEFORE installing Django.
- [Django]-Why does django run everything twice?
- [Django]-Is there a list of Pytz Timezones?
- [Django]-How to deal with "SubfieldBase has been deprecated. Use Field.from_db_value instead."
0๐
I wasted a lot of time on this. Turns out that the default database library is not supported for Python 3. You have to use a different one.
- [Django]-Update only specific fields in a models.Model
- [Django]-How to show processing animation / spinner during ajax request?
- [Django]-How do you dynamically hide form fields in Django?
0๐
if the error looks like this
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module:
dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded:
/usr/local/opt/mysql/lib/libmysqlclient.20.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_mysql.so
then try :
pip install python-mysqldb
- [Django]-Django select_for_update cannot be used outside of a transaction
- [Django]-Django models: get list of id
- [Django]-Django: Redirect to previous page after login
0๐
Faced similar issue. I tried installing mysql-python
using pip, but it failed due to gcc dependency errors.
The solution that worked for me
conda install mysql-python
Please note that I already had anaconda installed, which didnโt had gcc dependency.
- [Django]-Django Background Task
- [Django]-Effects of changing Django's SECRET_KEY
- [Django]-How do I check for last loop iteration in Django template?
0๐
try this, simply using pip:
On Windows the recommended command is:
python -m pip install mysqlclient
use it in a virtual environment
- [Django]-Django โ filtering on foreign key properties
- [Django]-Embedding JSON objects in script tags
- [Django]-Django Queryset with year(date) = '2010'
0๐
I had tried running different commands in this question. However none of them work for me in MXLinux. Itโs a Debian 11 based distro (As of writing this). So, this answer should be applicable to Debian also.
sudo apt-get install python3-dev default-libmysqlclient-dev
Then install mysql in your python environment
pip install mysqlclient
I have tested this against, Python==3.8.13. AFAIK, this will work with Pyenv, Conda, Pipenv, Poetry etc. too.
Note:- This may work with Latest Version of Debian Based distros like LinuxMint, KDE Neon, Zorin OS, Kubuntu, elementary OS, Pop!_OS, Linux Lite, Linuxfx, etc. too.
- [Django]-Alowing 'fuzzy' translations in django pages?
- [Django]-What is the best django model field to use to represent a US dollar amount?
- [Django]-How does the get_or_create function in Django return two values?
0๐
I was running into a similar problem and located the problem to be an improperly installed mysqlclient. Installation of mysqlclient on Windows using the pip channel was causing dependency issues.
Install mysqlclient with the command:
> pip install mysqlclient
If that doesnโt work, install just the mysqlclient binaries. This seemed to work for me.
> pip install --only-binary :all: mysqlclient
Following is how my ./projectName/settings.py looks.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'dbname',
'USER': 'user',
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '3306',
},
If you are going to use mysql-connector for the engine, then install the mysql-connector using
> pip install mysql-connector-python
And change the โENGINEโ of DATABASES in the settings.py file to โmysql.connector.djangoโ.
I recommend all of the pip installations using a virtual environment.
- [Django]-How can I check the size of a collection within a Django template?
- [Django]-How to create a user in Django?
- [Django]-MySQL "incorrect string value" error when save unicode string in Django
-1๐
Install (if not found):
pip install mysql.connector
Settings:
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '...',
'HOST': '...',
'PORT': '3306',
'USER': '...',
'PASSWORD': '...',
}
- [Django]-Charts in django Web Applications
- [Django]-Django py.test does not find settings module
- [Django]-Using Cloudfront with Django S3Boto
-1๐
Try this
apt-get install libmysqlclient-dev
and try again to install mysqlclient:
pip install mysqlclient
- [Django]-FileUploadParser doesn't get the file name
- [Django]-How can one use enums as a choice field in a Django model?
- [Django]-Django: accessing session variables from within a template?
-3๐
Maybe you can try the following mode of operation:
sudo python manage.py runserver 0.0.0.0:8000
- [Django]-Django multiple template inheritance โ is this the right style?
- [Django]-How to properly use the "choices" field option in Django
- [Django]-Django admin: How to display the field marked as "editable=False" in the model?