Error loading MySQLdb module "Have you installed mysqlclient or MySQL-python?"

I am using the Windows 10 command line for a django project using python34, however I ran into difficulties with SQL.

I already installed mysqlclient using pip install mysqlclient==1.3.5 and found the file to make sure that I was not delusional. Then I ran python manage.py migrate to transfer the tables to the SQL database (I use phpmyadmin). However, when the team returned with ...

  File "C:\Users\user\env\lib\site-packages\django\db\backends\mysql\base.py", line 30, in <module> 'Did you install mysqlclient or MySQL-python?' % e django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python? 

I know that such questions already exist, but not a single solution seems to have affected the attempts. Thank you in advance.

+25
source share
11 answers
 pip install pymysql 

Then edit the __init__.py file in the project source directory (same as settings.py)

add:

 import pymysql pymysql.install_as_MySQLdb() 
+110
source

Faced the same problem after switching to python 3. Apparently, MySQL-python is incompatible, therefore, according to django's official docs , installed mysqlclient using pip install mysqlclient on Mac. Please note that the documentation mentions some OS related issues.

Quoting from documents :

Background

You may need to install Python and MySQL development headers and libraries, for example:

sudo apt-get install python-dev default-libmysqlclient-dev # Debian / Ubuntu

sudo yum install python-devel mysql-devel # Red Hat / CentOS

brew install mysql-connector-c # macOS (Homebrew) (there is currently an error. See below)

Windows has binary disks that can be installed without MySQLConnector / C or MSVC.

Python 3 note: if you are using python3, you need to install python3-dev with the following command:

sudo apt-get install python3-dev # debian / Ubuntu

sudo yum install python3-devel # Red Hat / CentOS

MySQL Connector / C error note on macOS

See also: https://bugs.mysql.com/bug.php?id=86971

Versions of MySQL Connector / C may have incorrect default configuration parameters that cause compilation errors when mysqlclient-python installed. (As of November 2017, this is true for homegrown mysql-connector-c and the official package)

Modifying mysql_config solves these problems as follows.

+ Change

 # on macOS, on or about line 112: # Create options libs="-L$pkglibdir" libs="$libs -l " 

in

 # Create options libs="-L$pkglibdir" libs="$libs -lmysqlclient -lssl -lcrypto" 

An incorrect ssl configuration can also cause problems; see for example brew info openssl for details on macOS.

Install from PyPI

pip install mysqlclient

NOTE. Windows wheels may not be available with the original package. You must pin the version in your requirements.txt so as not to try to install the latest source package.

Install from source

  1. You can download the source code using git clone or zipfile .
  2. Configure site.cfg
  3. python setup.py install
+9
source

Use the command below to solve your problem,

 pip install mysql-python apt-get install python3-mysqldb libmysqlclient-dev python-dev 

Powered by Debian

+6
source

For pip

 pip install pymysql 

For pip3 you should use

 python3 -m pip install PyMySQL 

Then edit the init.py file in the source directory of your project (same as settings.py). Add:

 import pymysql pymysql.install_as_MySQLdb() 
+1
source

I had this problem quite recently, even using the mysqlclient library compatible with python 3, and mysqlclient managed to solve my problem, albeit a little unorthodox. If you are using MySQL 8, try and see if this helps! :)

I just made a copy of the libmysqlclient.21.dylib file located in my last install of MySQL 8.0.13, which was in /usr/local/mysql/lib and transferred that copy under the same name to /usr/lib .

You will have to temporarily disable security integrity protection on your Mac, but do it because you do not have or cannot change permissions for anything in /usr/lib without disabling it. You can do this by booting into the recovery system, click "Utilities" in the menu at the top and open a terminal and enter csrutil disable in the terminal. Remember to re-enable security integrity protection when you do! The only difference from the above process is that you run csrutil enable instead.

You can learn more about how to disable and enable macro protection integrity protection.

0
source

For pip

 pip install pymysql For pip3 you should use python3 -m pip install PyMySQL 

Then edit the __init__.py file in the source directory of your project (same as settings.py)

add:

 import pymysql pymysql.install_as_MySQLdb() 
0
source

File "/ home / new / myblog / myblog / init .py", line 1, when importing MySQLdb ImportError: No module named 'MySQLdb' executed, mas deu esse erro.

0
source

Installing mysqlclient using anaconda quite simple and straight forward .

 conda install -c bioconda mysqlclient 

and install pymysql using pip.

 pip install pymqsql 
0
source

edit the init.py file in your project directory

 import pymysql pymysql.install_as_MySQLdb() 
-1
source

Try running apache and mysql on xampp. It works for me.

-3
source

Use the command below to solve your problem,

 pip install mysql-python 

And do not send questions before the correct search, these questions have been questioned and answered, see the link below

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: no module named MySQLdb

-5
source

Source: https://habr.com/ru/post/1272838/


All Articles