Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Did you install mysqlclient?

I have read every single post and googled for the last 4 hours to try to find a solution to this error.

I am not running virtual environment, this server is just for django.
Server: Ubuntu 16.04
python: 3.5.2

I am getting this error

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

trying to install mysqlclient

sudo -H pip3 install mysqlclient
Requirement already satisfied: mysqlclient in /usr/local/lib/python3.5/dist-packages (1.3.12)

using ubuntu

sudo apt-get install -y python3-mysqldb
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-mysqldb is already the newest version (1.3.7-1build2).
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

Any help is greatly appreciated

like image 561
Marc Wolf Avatar asked Jun 21 '18 13:06

Marc Wolf


3 Answers

MySQL client did not install properly. For that this module did not find. So why it returned this error message. Bellow my practical codes, that I solved this problem. Hopefully might your.

Go to your command terminal and type [Based on Operating System(Windows, Mac Os, Linux)]

You may upgrade setuptools package If not updated

pip install --upgrade setuptools

Then install python mysql

pip install pymysql

Then edit the init.py file in project root directory (where settings.py file located)

import pymysql
pymysql.install_as_MySQLdb()

Edit the settings.py file on root directory:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'database name',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '127.0.0.1',  // If localhost
        'PORT': '3306',  // your database running port
    }
}

That's it. I hope, I shall be able to little help you. If any problem, please comments me.

like image 158
Subarata Talukder Avatar answered Oct 02 '22 00:10

Subarata Talukder


I had the same problem and here is a fast and easy solution:

sudo apt-get install libmysqlclient-dev
like image 30
hellyworld Avatar answered Oct 01 '22 22:10

hellyworld


some time you got this type error when trying to install the mysqlclient

  ERROR: Command errored out with exit status 1:
 command: /home/alen/Desktop/django_admin/admindashboard/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-0_fdpfs5/mysqlclient/setup.py'"'"'; __file__='"'"'/tmp/pip-install-0_fdpfs5/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-0_fdpfs5/mysqlclient/pip-egg-info
     cwd: /tmp/pip-install-0_fdpfs5/mysqlclient/
Complete output (12 lines):
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-install-0_fdpfs5/mysqlclient/setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/tmp/pip-install-0_fdpfs5/mysqlclient/setup_posix.py", line 65, in get_config
    libs = mysql_config("libs")
  File "/tmp/pip-install-0_fdpfs5/mysqlclient/setup_posix.py", line 31, in mysql_config
    raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found
----------------------------------------ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

you installed the pymysql but no effect in there then plese try the following command

     sudo apt-get install python3-dev default-libmysqlclient-dev build-essential #for debin

after install this then run

 pip install mysqlclient
like image 30
Alan Jose Tom Avatar answered Oct 02 '22 00:10

Alan Jose Tom