33

I just upgraded my Ubuntu install to 16.04 and this seems to have broken my mysql dependencies in the MySQL-python package.

Here is my error message:

  File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
return strategy.create(*args, **kwargs)
  File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 75, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/opt/monitorenv/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 92, in dbapi
return __import__('MySQLdb')
  File "/opt/monitorenv/local/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

So basically the import_mysql is looking for an so file that doesn't exist because in Ubuntu 16.04, I have libmysqlclient20 installed. And libmysqlclient18 is not available. As far as I am aware (or at least I believe) my python libraries are up to date with the latest versions.

(I tried running pip install --upgrade mysql-python which indicated it was up to date).

Do you guys have any suggestions ?

RyanH
  • 759
  • 1
  • 8
  • 13

8 Answers8

47

Thank for Largaroth. If you use mysqlclient on Ubuntu 16.04 and have error: ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

You can fix:

sudo -H pip uninstall mysqlclient

sudo -H pip install --no-binary mysqlclient mysqlclient
Cuong Tran
  • 1,909
  • 1
  • 20
  • 21
27

I ended up finding the solution to my problems with pip install --no-binary MySQL-python MySQL-python as stated in this thread : Python's MySQLdb can’t find libmysqlclient.dylib with Homebrewed MySQL

Community
  • 1
  • 1
RyanH
  • 759
  • 1
  • 8
  • 13
  • Wish I could upvote this more than once. In the past week I've run into this problem multiple times. The answer is not too easy to find unfortunately. – Bono Jan 03 '17 at 16:56
  • 1
    For those stumbling along hitting a `no such option: --no-binary` error: make sure to upgrade your version of pip first! – ShaneOH Mar 28 '17 at 02:33
8

I had the same issue. I uninstalled and reinstalled MySQL-python:

pip uninstall MySQL-python
pip install MySQL-python
Warren O'Neill
  • 608
  • 6
  • 6
2

I had this issue on updating to stretch. To fix it I updated my requirements.txt:

mysqlclient==1.4.2.post1

So either update that manually or pip install --upgrade mysqlclient

Mark
  • 297
  • 2
  • 9
1

My problem was that I was using wheelhouse from old OS.

The problem was solved when I uninstalled/installed the package or updated wheelhouse...

From docs:

http://mysql-python.sourceforge.net/FAQ.html#importerror

This means you have a version of MySQLdb compiled against one version of MySQL, and are now trying to run it against a different version. The shared library version tends to change between major releases.

Solution: Rebuilt MySQLdb, or get the matching version of MySQL.

Community
  • 1
  • 1
confiq
  • 2,795
  • 1
  • 26
  • 43
1

Steps:

  1. search mysql path

    which mysql

    O/p : /opt/mysql/

  2. create Symbolic Links to usr/lib

    sudo ln -s /opt/mysql/lib/mysqlclient.so.20 /usr/lib

Note: mysqlclient.so.20 will be as per your version

Anmol Mourya
  • 530
  • 5
  • 7
0

I had this issue with python 3.6... when I used an environment with Python 3.5 it worked just fine.

Kyle
  • 98
  • 6
0

I solved this on my virtual environment using django 2.2.7 and Ubuntu 19.10 by doing:

pip3 uninstall mysqlclient

pip3 install mysqlclient

FelipeGTX
  • 91
  • 1
  • 1
  • 8