I am using Python version 2.5.4 and install MySQL version 5.0 and Django. Django is working fine with Python, but not MySQL. I am using it in Windows Vista.
score:0
Win10 / Python27 this worked for me:
easy_install mysql-python
all other 'pip install...' failed with dependency errors
score:0
When I ran the command apt-get install python-mysqldb, I still encountered the error message below
mysql_config not found when installing mysqldb python interface
So I first had to run the command below
sudo apt-get install libmariadbclient-dev
If you use MySQL instead of MariaDB, run the following instead
Then run
apt-get install python-mysqldb
Then now run
pip install mysqlclient
Some more answer related to the same question
- No module named MySQLdb
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- Python3 + MySql: Error loading MySQLdb module: No module named 'MySQLdb'
- Error loading MySQLdb module: No module named 'MySQLdb'
- Django manage.py syncdb throwing No module named MySQLdb
- Django AWS Elastic Beanstalk error ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
- Django on AWS Elastic Beanstalk - No module named MySQLdb Error
- django - Error loading MySQLdb module: No module named MySQLdb
- VirtualEnv ImportError: No module named MySQLdb
- Getting “Error loading MySQLdb module: No module named MySQLdb” in django-cms
score:0
For CentOS 8
and Python3
$ sudo dnf install python3-mysqlclient -y
score:1
On my mac running Catalina v10.15.2, I had the following MySQLdb version conflict:
ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 4, 6, 'final', 0)
To resolve it, I did the following:
pip uninstall MySQL-python
pip install MySQL-python
Related question
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
- Not able to use mysql in google app engine - Error loading MySQLdb module: No module named _mysql. I am using cloudSQL
- No module named pkg_resources
- ImportError: No module named 'django.core.urlresolvers'
- django import error - No module named core.management
- Django Rest Framework -- no module named rest_framework
- Django - "no module named django.core.management"
- Error: No module named psycopg2.extensions
- Django import error - no module named django.conf.urls.defaults
- Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'
score:1
Faced this issue with mysql.connector.python version 8.0.24 on mac(if code base is same then the issue should happen in windows as well). This file on line 51 imports "from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper". The imported file has following code 14-20(exact code and error that you received is part of code
try:
import MySQLdb as Database
except ImportError as err:
raise ImproperlyConfigured(
'Error loading MySQLdb module.\n'
'Did you install mysqlclient?'
) from err
The error is formed here. Not sure why this import keeps coming back in different version of mysql connector but 8.0.23 does not have the import, so I reverted to that version and error was gone... This is incase you wish to continue to work with mysql.connector.python
score:2
I have tried methods above, but still no module named 'MySQLdb', finally, I succeed with
easy_install mysql-python
my env is unbuntu 14.04
score:2
On OSX these commands worked for me
brew install mysql-connector-c
pip install MySQL-python
score:2
If your are using SQLAlchemy and the error is in /site-packages/sqlalchemy/dialects/mysql/mysqldb.py
:
from ...connectors.mysqldb import (
MySQLDBExecutionContext,
MySQLDBCompiler,
MySQLDBIdentifierPreparer,
MySQLDBConnector
)
so you may have missed mysqldb connector for SQLAlchemy
and the solution is to re-install sqlalchemy after installing mysql-python
module.
score:2
None of the above worked for me on an Ubuntu 18.04 fresh install via docker image.
The following solved it for me:
apt-get install holland python3-mysqldb
score:3
For Python 3+ version
install mysql-connector
as:
pip3 install mysql-connector
Sample Python DB connection code:
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd=""
)
print(db_connection)
Output:
> <mysql.connector.connection.MySQLConnection object at > 0x000002338A4C6B00>
This means, database is correctly connected.
score:3
On Debian Buster, the following solution worked for me with python 3.7:
sudo apt-get install libmysqlclient-dev
sudo apt-get install libssl-dev
pip install mysqlclient
score:3
Python 3
Make sure the import order:
#BAD
import MySQLdb # <------ NOT here
import pymysql
pymysql.install_as_MySQLdb()
#GOOD
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb # <------- HERE!
score:4
If you are running on Vista, you may want to check out the Bitnami Django stack. It is an all-in-one stack of Apache, Python, MySQL, etc. packaged with Bitrock crossplatform installers to make it really easy to get started. It runs on Windows, Mac and Linux. Oh, and is completely free :)
score:4
Thanks to derevo but I think there's another good way for doing this:
- Download and install ActivePython
- Open Command Prompt
- Type
pypm install mysql-python
- Read the notes specific to this package.
I think pypm
is more powerful and reliable than easy_install
.
score:5
- Go to your project directory with
cd
. - source/bin/activate (activate your env. if not previously).
- Run the command
easy_install MySQL-python
score:6
pip install --user mysqlclient
above works for me like charm for me.I go the error from sqlalchemy actually. Environment information :
Python : 3.6, Ubuntu : 16.04,conda 4.6.8
score:6
I personally recommend using pymysql
instead of using the genuine MySQL connector, which provides you with a platform independent interface and could be installed through pip
.
And you could edit the SQLAlchemy URL schema like this:
mysql+pymysql://username:passwd@host/database
score:7
I met the same situation under windows, and searched for the solution.
Seeing this post Install mysql-python (Windows).
It points out installing such a pip environment is difficult, needs many other dependencies.
But I finally know that if we use mysqlclient
with a version down to 1.3.4
, it don't need that requirements any more, so try:
pip install mysqlclient==1.3.4
score:9
Python 3.8
sudo apt-get install libmysqlclient-dev
sudo apt-get install -y python3-mysqldb
pip3 install pymysql
settings.py
import pymysql
pymysql.install_as_MySQLdb()
score:10
For Python 3.6+
sudo apt-get install libmysqlclient-dev
pip3 install mysqlclient
does the trick
score:13
Try this.
pip install MySQL-python
score:13
If pip install mysqlclient produces an error and you use Ubuntu, try:
sudo apt-get install -y python-dev libmysqlclient-dev && sudo pip install mysqlclient
score:17
For anyone coming to this page when trying to find a solution for sqlalchemy
, all you need to do is:
pip install PyMySQL
And adjust your connection string to use PyMySQL, from mysql://
to mysql+pymysql://
.
score:18
pip install PyMySQL
and then add this two lines to your Project/Project/init.py
import pymysql
pymysql.install_as_MySQLdb()
Works on WIN and python 3.3+
score:22
for Windows :
pip install mysqlclient pymysql
then:
import pymysql
pymysql.install_as_MySQLdb()
for python 3 Ubuntu
sudo apt-get install -y python3-mysqldb
score:24
I am at ubuntu (linux) and what worked for me was
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
and then finally
pip install mysqlclient
score:32
Note this is not tested for python 3.x
In CMD
pip install wheel
pip install pymysql
in settings.py
import pymysql
pymysql.install_as_MySQLdb()
It worked with me
score:36
Ubuntu:
sudo apt-get install python-mysqldb
score:49
mysqldb
is a module for Python that doesn't come pre-installed or with Django. You can download mysqldb
here.
score:94
if your python version is 3.5
, do a pip install mysqlclient
, other things didn't work for me
score:170
...and remember there is no MySQLdb for python3.x
(I know the question is about python2.x but google rates this post quite high)
EDIT: As stated in the comments, there's a MySQLdb's fork that adds Python 3 support: github.com/PyMySQL/mysqlclient-python
score:722
You need to use one of the following commands. Which one depends on what OS and software you have and use.
- easy_install mysql-python (mix os)
- pip install mysql-python (mix os/ python 2)
- pip install mysqlclient (mix os/ python 3)
- apt-get install python-mysqldb (Linux Ubuntu, ...)
- cd /usr/ports/databases/py-MySQLdb && make install clean (FreeBSD)
- yum install MySQL-python (Linux Fedora, CentOS ...)
For Windows, see this answer: Install mysql-python (Windows)
Credit To: stackoverflow.com
Related Query
- Gunicorn, no module named 'myproject
- ImportError: No module named virtualenv
- django.core.exceptions.ImproperlyConfigured: Error loading psycopg module: No module named psycopg
- "No module named simple" error in Django
- Running django tutorial tests fail - No module named polls.tests
- ImportError: No module named django.core.wsgi Apache + VirtualEnv + AWS + WSGI
- ImportError: No module named django_filters
- No module named 'polls.apps.PollsConfigdjango'; Django project tutorial 2
- No module named django but it is installed
- ImportError: No module named django.core.handlers.wsgi in install django mod_wsgi config on apache
More Query from same tag
- Anonymous user error
- Remove contents of <style>...</style> tags using html5lib or bleach
- Django testing using GeoDjango + PostGIS
- import m2m relation in django-import-export
- Django float format get only digits after floating point
- How can I model a database view in Django if it doesn't have a primary key?
- How to read google calendar events of user after getting access token?
- Django deployment: configuring correct python to be used by apache/mod_wsgi
- indentation problem in my python program
- Using boto, set content_type on files which are already present on s3
- django celery error: Unrecoverable error: AttributeError("'EntryPoint' object has no attribute 'module_name'")
- why data is varying from sqlite database to django template(tab spaces are removed)?
- Why is my user model not appearing with the correct name and fields in django admin
- Django Tastypie Import Error on resources
- Django: handle CSRF error as form error