Forums

MySQL setup for Python/Django failing on mysql-python library.

Having trouble with the mySQL setup. It looked straightforward in the help pages, but seems to consistently throw an error for me.

I have set up a database with the setup procedure from help page, using the "Databases" tab in the dashboard, and then I verified that the database setup was okay by doing a shell-based session:

mysql -u USERNAME -h HOSTNAME -p 'USERNAME$DATABASENAME'

that looked okay. So I assume the DB setup was good. On to python and Django

Then I did a pip install of mysql-python inside the virtualenv where I am working in. But when I try to use the MySQLdb library it fails like this:

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/playica/.virtualenvs/assur/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

Outside the virtualenv I can do an import and it doesn't complain.

I have also set up my Django settings file with the database ENGINE, USER, PASSWORD, NAME and HOST, and using django fails with a similar library fail. It's set up with that same virtualenv.

I tried pip uninstall and re-install of mysql-python, but it still fails the same way.

Thought I was following the help pages to the letter - did I miss something?

-Ross.

Please run

pip install --force-reinstall --no-binary :all: MySQL-python==1.2.5

in your virtualenv.

Could you tell us what help page were you following so we may see if it is not misleading somehow?

Thanks for the fix, that seems to work for me.

Oh yes, here is a the link to the help page that could probably use a tweak. It confirmed for me that pip install was required to use MySQL, but didn't clarify that a force reinstall etc might be required.

 https://help.pythonanywhere.com/pages/UsingMySQL

Thanks again.

-Ross.

Thanks! The help page is now updated.