I am new to Django and I try to follow the official tutorial. since I want to connect to mysql (installed on my computer, and i checked mysql module does exit in python command line), I set the ENGINE in setting.py to be django.db.backends.mysql . and then I tried to run
python manage.py syncdb
then I got error message like this:
Error loading MySQLdb module
and I cannot run
pip install mysql-python
the error msg is:
Unable to find vcvarsall.bat
so what is this error? and honestly I am not sure about the difference between mysql-python and mysql-connector-python. Since i tried with "pip install mysql-connector-python" and it tells me that requirement already satisfied...
You need to download the windows binary installer for the MySQL drivers for Python. Installing from source will not work since you do not have the development headers in Windows.
You need to install the mysql python connector
sudo apt-get install python-mysqldb
Related
I am working on the setup of my first unmanaged vps(ubuntu 20.4) and following the document to connect my django site to mysql server "https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database"
able to setup
python/django/virtualenv
mysql server - tested from mysql workbench on my local machine-Ok
apache2 working ok. able to see the welcome screen with sqlite3.
now moving to mysql. i tried both the way('ENGINE': 'django.db.backends.mysql' and option file '/etc/mysql/my.cnf' to connect to mysql server from django project.
None of the alternatives working. activated virtualenv, installed mysqldb using
a) sudo apt install libmysqlclient-dev default-libmysqlclient-dev
b) pip install wheel
c) pip install mysqlclient
while trying to migrate following error encountered. tried with all the option available on stakoverflow, i found none of them working.
Error:
"
(envFusion) worker#server:~/fusion/fusionerp$ python manage.py makemigrations
Traceback (most recent call last):
File "/home/worker/fusion/envFusion/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 15, in
import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'
The above exception was the direct cause of the following exception:
.
.
File "/home/worker/fusion/envFusion/lib/python3.8/site-packages/django/db/backends/mysql/base.py", line 17, in
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient? "
with ubuntu 20.04 deafult python version is 3.8 and connecting to mysql with 3.8 is a bit challenge so you need to downgrade python to 3.6 or downgrade to ubuntu 18 if you are starting a fresh.
Found a tutorial to downgrade using alternatives and it worked. But had my other dependencies where i need python >= 3.7. So i had no other choice but refresh my ubuntu 20.04 on vps and configured with postgres. it is working way better than i expected with apache2/restframework/redis.
i suppose that i have a solution to this problem, so when we use a Ubuntu OS, i think that we need to run the next commands to work that package:
sudo apt-get install default-libmysqlclient-dev -y
sudo apt-get install gcc -y
pip3 install mysqlclient
Even if you already tried the first one, it might work. I have a Dockerfile in my GitHub of a Django app, if you want to test it later to see if it works on your machine, it took me a week to find the problem and deploy this app to Oracle Cloud because of this error.
Dockerfile
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
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
Hi all I am tried to install the superset on OSX using the Python3. After the installation finished when I tried to add the Database using the mysql:// it said error No Module name MySQLDb. I tried to explore how to solved this, one of tutorial said try to install mysqlclient using pip3 install mysqlclient failed to install with error code mysql.h not found.
Than I following another tutorial used the mysql-connector. After I installed it, finally I can connect to mysql DB and insert table to the system. But when I tried to run the analysis from superset it said no data. Also I tried using SQL Lab and got the error args.
Updated: on my superset currently I am used the mysql+mysql-connector as URI Database connected properly, but when I tested to run a query it said execute() got an unexpected keyword argument 'args'. How to solve this?
Anyone have experience with this problem?
Thanks
Here is what works for me:
brew install python || true
brew install mysql || true
# Required for mysqlclient, see brew info openssl
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
# And now it works
pip3 install mysqlclient
Cheers!
Finally I got it working now.
What I am doing is reinstall the superset, run the brew install mysql-connector-c than run pip install mysqlclient
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.