19

I had a running django project and for some reasons I had to remove the current mysql version and install a different MySQL version in my machine.

But now when I am trying to run this program am getting an error as follows:

raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libmysqlclient.so.20: cannot open shared object file: No such file or directory
dds
  • 2,335
  • 1
  • 31
  • 45
Dawn T Cherian
  • 4,968
  • 3
  • 24
  • 35

7 Answers7

19

reinstall the c shared library:

pip uninstall mysql-python
pip install mysql-python
Chalist
  • 3,160
  • 5
  • 39
  • 68
  • This works for Ruby on Rails projects as well. Comment `gem 'mysql2'` in the Gemfile, run `bundle install`, uncomment the line and run `bundle install` again. – 3limin4t0r Jan 25 '22 at 15:41
18

My issue with the same error message was mysql environment not all the way set up. I needed to uninstall MySQL-python; install libmysqlclient-dev; reinstall MySQL-python to rectify the issue.

So the fix was too:

  • sudo pip uninstall MySQL-python (uninstall from your package manager of choice)
  • sudo apt-get install libmysqlclient-dev

  • sudo pip install MySQL-python

**I should also mention that I used the --no-cache-dir option with pip install to hit PYPI directly which helped discover the following:

sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup.py", line 17, in <module>
    metadata, options = get_config()
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/tmp/pip-build-Y7RFpJ/mysql-python/setup_posix.py", line 25, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

and lead me to here

Using: mysql 5.7, mysql-python 1.2.5, django 1.8.9, ubuntu 16.04

Community
  • 1
  • 1
Darnell Lynch
  • 181
  • 1
  • 3
2

Use the following commands:

pip uninstall mysql-python
pip install mysql-python

In my case it work because it searches from the complied files.

jherran
  • 3,337
  • 8
  • 37
  • 54
Devendra Mishra
  • 77
  • 3
  • 10
2

I did fix the same issue via setting below environment variable:

export LD_LIBRARY_PATH=/usr/local/mysql/lib
Pondor
  • 21
  • 1
  • That worked for me !, thanks to elaborate more how to find the path i asked yum ( in using ami linux ) by using: yum whatprovides "*libmysqlclient*" from the output i couldl find the library folder that had libmysqlclient.so and added it to LB_LIBRARY_PATH on my bash_profile export LD_LIBRARY_PATH=/usr/lib64/mysql57 – luster Jul 18 '18 at 15:59
2

In my case the problem was caused by Ubuntu upgrades, so I can't find libmysqlclient.so.20 in /usr/lib/x86_64-linux-gnu.

Solution:

  1. Check existance libmysqlclient.so.XX in /usr/lib/x86_64-linux-gnu (or similar)
  2. Download libmysqlclient.so.XX from Ubuntu website (eg. link for v20)
  3. Install lib using dpkg command sudo dpkg -i libmysqlclient(...).deb and sudo apt-get install -f
  4. Link lib: ln -s /usr/lib/x86_64-linux-gnu/libmysqlclient.XX.so libmysqlclient.XX.so
Lukasz Koziara
  • 4,274
  • 5
  • 32
  • 43
  • 1
    Lukasz, I just posted a very similar but slightly simpler answer here: https://unix.stackexchange.com/a/623845/7155 ...in case you need to do it again. – Karl Wilbur Dec 10 '20 at 15:53
0

just in case pip uninstall & pip install not working, and you dont want to set specific path to ld_library_path, what I did on my vps:

cd /usr/local/lib
sudo ln -s /path/to/your/libmysqlclient.so.20

in my case my mysql is installed from linuxbrew (there is some reason to install inside home), so I had to navigate there $HOME/.linuxbrew/Cellar/mysql/5.7.18/lib/libmysqlclient.so.20

Artiko
  • 69
  • 1
  • 3
  • 8
0

I had the same problem and I fixed making what the mysqlclient official doc says to install before: sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

Reidel
  • 347
  • 2
  • 13