Manage runserver - Error loading MySQLdb module - mysql

4 Django 1.8 and I have installed pip
I try use command manage runserver but it show me
File "C:\Python34\lib\site-packages\django\db\backends\mysql\base.py", >line 27, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'
I have installed mysql-installer-community-5.7.10.0
and to fix me problem I try install pip install mysqlclient or mysql-python but I hade the same reasults like on the image below
CMD printscreen

the practice is to install venv :
sudo pip install virtualenv
source env/bin/activate
From there you can install first Django and after mysqlclient
sudo pip install django
sudo pip install mysqlclient
I had that problem also and I was forced to uninstall django and python and reinstall it.
Try to reinstall Django first

Related

Problem installing mysqlclient for Django project (macOS)

When connecting my Django project to a database hosted on a remote VM, when I run python3 manage.py run server I get the error
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
when I try python3 -m pip install mysqlclient to resolve the dependency, I get the error
ERROR: Could not find a version that satisfies the requirement mysqlclient (from versions: 1.3.0, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.3.8, 1.3.9, 1.3.10, 1.3.11rc1, 1.3.11, 1.3.12, 1.3.13, 1.3.14, 1.4.0rc1, 1.4.0rc2, 1.4.0rc3, 1.4.0, 1.4.1, 1.4.2, 1.4.2.post1, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 2.0.0, 2.0.1, 2.0.2, 2.0.3)
ERROR: No matching distribution found for mysqlclient
I'd like to understand what is causing these issues and how to resolve it.
Thanks in advance!
I got it to work! For anyone facing the same issues run brew install mysql then try python3 manage.py runserver
For what it's worth, you might try installing the mysql-connector-c first. It seems heavy-handed to have to install MySQL to use a driver.
From:
How to install Python MySQLdb module using pip?
Mac OS
brew install mysql-connector-c
if that fails, try
brew install mysql

Error loading MySQLdb module. Did you install mysqlclient? on MacOS

Am Trying to connect to my mysql db from django app.
I get the below error during migration:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module. Did you install mysqlclient?
I've already installed mysqlclient as below:
Requirement already satisfied: mysqlclient in
/usr/local/lib/python3.7/site-packages (1.4.2.post1)
I've also tried with pymysql and adding below code to ini.py file:
import pymysql
pymysql.install_as_MySQLdb()
Gives me some other errors.
What could be wrong?
Python 3.7 , mysql 5.7 and Django 2.2 are my setup versions.
I had the same issue. Running the below command fixed it for me.
pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient
I had the same issue. The thing that worked for me is the following:
https://stackoverflow.com/a/54521244/12497648,
except when I did brew install mysql-client
I got the message Warning: mysql-client 5.7.23_1 is already installed and up-to-date
To reinstall 5.7.23_1, run "brew reinstall mysql-client" so I ran brew reinstall mysql-client after which I continued with the instructions from the link above (export PATH... etc.)
(also don't forget to do the pip wheel mysqlclient / pip install mysqlclient)
If the error includes a Reason: image not found error, then it can be solved with symlinks like this:
Library not loaded: #rpath/libmysqlclient.21.dylib Reason: image not found Django migrate error using mysqlclient DB driver and MySQL 8 with macOS

Fresh python 3.7 / django 2.2.1 installation not recognising that mysqlclient is installed

I have a brand new django 2.2.1 project I have just installed into a python 3.7 virtualenv on OS X (10.14.4). After some frustrations I got mysqlclient to install but when I run the django dev server it doesn't recognise that it is installed:
Here are the steps I've taken so far:
brew install mysql
pipenv --three
pipenv install django==2.2.1
pipenv install mysqlclient
brew uninstall mysql
brew install mysql-connector-c
pipenv install mysqlclient
brew unlink mysql-connector-c
brew install mysql
django-admin startproject projectname
Now, the only change I have made to the out-of-the-box django installation is to change the default database backend to django.db.backends.mysql and when I run the django server I get the following:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
However, going back to the virtualenv and doing "pip install mysqlclient" gives:
Requirement already satisfied: mysqlclient in /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages (1.4.2.post1)
Any ideas why django can't see the mysqlclient installed in the virtualenv? I can confirm that all of the above has been run in the virtualenv. I suspect it has something to do with the faff that OSX makes you go through to install it but I'm not sure how to pick it apart.
I have also tried to replace mysqldb with pymysql as suggested here but that causes the server to give a different error:
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
Mysql is a given for this project so use of an alternative backend is not an option. Any help very gratefully received, many thanks in advance.
UPDATE: Output of pip freeze:
Django==2.2.1
django-auth-ldap==1.7.0
Markdown==3.1
mysql-connector-python==8.0.16
mysqlclient==1.4.2.post1
protobuf==3.7.1
pyasn1==0.4.5
pyasn1-modules==0.2.5
PyMySQL==0.9.3
pyodbc==4.0.26
python-ldap==3.2.0
pytz==2019.1
simplejson==3.16.0
six==1.12.0
sqlparse==0.3.0
xmltodict==0.12.0
UPDATE 2:
Following conor's post (thanks conor) I started again with a fresh virtualenv and again successfully installed mysqlclient1.4.2.post1. Here's the output from pip freeze now:
Django==2.2.1
mysqlclient==1.4.2.post1
pytz==2019.1
sqlparse==0.3.0
Still getting the same error when I do python manage.py runserver though:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
UPDATE 3:
Thought I would try importing the MySQLdb module on the python command line to see if I can get any more insight and it returns the following:
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Expected in: flat namespace
in /Users/<username>/.local/share/virtualenvs/<projectname>-KrUE_JNo/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
SOLVED
So it looks like the issue was that on initial installation the mysqlclient library had compiled against the wrong version of mysql (not sure how that happened), so I had to force it to recompile.
Here are the steps:
brew uninstall mysql
brew uninstall myysql-connector-c
pipenv uninstall mysqlclient
brew install mysql-connector-c
At this point we need to update /usr/local/bin/mysql_config as per the instructions that conor linked to (thanks again conor), i.e. change the line that read
libs="$libs -l "
to
libs="$libs -lmysqlclient -lssl -lcrypto "
Then, to fix the resultant "library not found for -lssl" error I used the answer from this question:
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
Then finally force mysqlclient to recompile and reinstall mysql:
pip install --force-reinstall --ignore-installed --no-binary :all: mysqlclient
brew unlink mysql-connector-c
brew install mysql
Thanks to everyone who took time to help out!
If you're on macos do this
$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python
and follow the instructions here: https://pypi.org/project/mysqlclient/
Downgrading from python 3.7.4 to python 3.6 solved the issue for me on windows 10.

Mac OS Mojave Import MySQLDB import trouble

I'm trying to run a program in Python 2.7, when I run the program it says
import MySQLdb
ImportError: No module named MySQLdb.
I've tried to install MySQL using the command "brew install MySQL-connector-c" which worked but still gave me the error when running the program.
If brew install mysql-connector-c does not work on Mac OS, you can try:
brew install mysql
or
pip install MySQL-python
or
pip install mysqlclient

Docker: ModuleNotFoundError: No module named 'MySQLdb'

import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
I'm using Docker to serve a django app. Using Python3 and tried everything but the container is still not working.
-Tried installing:
pip install pymysql
pip install mysql
pip install mysql-connector
pip install msqlclient
-Added these two lines:
import pymysql
pymysql.install_as_MySQLdb()
to manage.py, init.py and wsgi.py
Also installed libmysqlclient-dev
The app is up and running in my local env, but when I push a container image the app won't start. I'm pretty sure that "pymysql.install_as_MySQLdb()" should do the trick, but for some reasons it is not getting executed.
Any ideas?