Docker: ModuleNotFoundError: No module named 'MySQLdb' - mysql

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?

Related

Error ModuleNotFoundError: No module named 'pymysql'

I have a problem with my project, I installed the "pymysql", but i am trying to use the "pymysql", but i try to use and gives the following error: ModuleNotFoundError: No module named 'pymysql'
pip install pymysql
import pymysql
ModuleNotFoundError: No module named 'pymysql'
I fixed this on my pc too it took me 1 day :)
So go to your cmd or terminal and write:
pip uninstall pymysql
python -m pip --upgrade pip
pip install pymysql
This will fix it as the version of pip u are using cant build a wheel for the module
Hope u will fix it :)

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

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

Manage runserver - Error loading MySQLdb module

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

Heroku hosting flask app with MySQL throwing errors

I'm new to Flask and heroku but I built a simple app and pushed it to heroku using SQLite. After migrating the app to a remote mysql db I noticed that can't get the app running because I'm getting the following error:
ImportError: No module named MySQLdb
After searching around I found that this error is because I need to install pip install mysql-python
However, my requirements.txt file already contains mysql-python
$ pip freeze
Flask==0.10.1
Flask-Login==0.3.2
Flask-Migrate==1.6.0
Flask-SQLAlchemy==2.1
Flask-Script==2.0.5
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23
MySQL-python==1.2.5
PyYAML==3.11
SQLAlchemy==1.0.9
Werkzeug==0.10.4
...
When I run bash on heroku it says that I've already met the requirements:
~ $ heroku run bash
Running bash on blank-places-7646... up, run.9708
~ $ pip install mysql-python
Requirement already satisfied (use --upgrade to upgrade): mysql-python in ./.heroku/python/lib/python2.7/site-packages
~ $ pip freeze
alembic==0.8.3
Flask==0.10.1
Flask-Login==0.3.2
Flask-Migrate==1.6.0
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23
MySQL-python==1.2.5
pbr==1.8.1
python-editor==0.4
SQLAlchemy==1.0.9
stevedore==1.9.0
Werkzeug==0.10.4
~ $ pip install mysql-python --upgrade
Requirement already up-to-date: mysql-python in ./.heroku/python/lib/python2.7/site-packages
Where am I going wrong?
MySQL is an addon on Heroku so try installing ClearDB.
heroku addons:add cleardb
https://elements.heroku.com/addons/cleardb
What worked for me:
I moved the MySQL connection to a separate file and did my calculations there. Returned the results to the main routes file as a json.
I suspect that heroku doens't all MySQL connections in the same file where you have routing set up.