Forums

mysql ModuleNotFoundError

I'm getting an error when starting my application:

Error running WSGI application
2018-10-26 14:14:50,266: ModuleNotFoundError: No module named 'mysql'
2018-10-26 14:14:50,267:   File "/var/www/frdhont_pythonanywhere_com_wsgi.py", line 16, in <module>
2018-10-26 14:14:50,267:     from main import app as application  # noqa
2018-10-26 14:14:50,267: 
2018-10-26 14:14:50,268:   File "/home/frdhont/mysite/main.py", line 7, in <module>
2018-10-26 14:14:50,268:     from functions import User, Model, validate_new_model_fields
2018-10-26 14:14:50,268: 
2018-10-26 14:14:50,268:   File "/home/frdhont/mysite/functions.py", line 4, in <module>
2018-10-26 14:14:50,268:     import mysql.connector

Full log files: https://www.pythonanywhere.com/user/frdhont/files/var/log/frdhont.pythonanywhere.com.error.log

I have checked pip install for mysql and mysqlclient in my virtual environment (I'm running Python 3.6), and they are both installed. I've even uninstalled and reinstalled them.

I've searched through the specific support page (https://help.pythonanywhere.com/pages/DebuggingImportError/), but no success.

Any tips?

  1. from a python console, does the import mysql.connector work?
  2. which python are you using- is your webapp using the same python? (ie. if you are using a virtualenv, have you specificied your webapp to use the virtualenv python and reloaded your webapp? if you are using the system version python3.6 for your webapp, did you pip3.6 install everything or did you pip install your libraries?)

Hello,

When I import mysql.connector in a console I get the following error:

mysite: unable to open X server `' @ error/import.c/ImportImageCommand/364.

I'm running python 3.6 in my web app and in the virtualenv. When I do pip3.6 install mysql, I get the same error message as when I do pip install..

Can you give the full command and the full traceback, and whether you are in a virtualenv or using the system python?

Hi Conrad,

I'm using a virtualenv, pyhton 3.6.

I've provided the full error message above, but here it is again:

Error running WSGI application
2018-10-26 14:14:50,266: ModuleNotFoundError: No module named 'mysql'
2018-10-26 14:14:50,267:   File "/var/www/frdhont_pythonanywhere_com_wsgi.py", line 16, in <module>
2018-10-26 14:14:50,267:     from main import app as application  # noqa
2018-10-26 14:14:50,267: 
2018-10-26 14:14:50,268:   File "/home/frdhont/mysite/main.py", line 7, in <module>
2018-10-26 14:14:50,268:     from functions import User, Model, validate_new_model_fields
2018-10-26 14:14:50,268: 
2018-10-26 14:14:50,268:   File "/home/frdhont/mysite/functions.py", line 4, in <module>
2018-10-26 14:14:50,268:     import mysql.connector

This error occurs on the following line:

import mysql.connector

When I enter this command manually in a bash console in my virtualenv, I get this error (also provided above)

mysite: unable to open X server `' @ error/import.c/ImportImageCommand/364.

Screenshot:

Bash screenshot

import mysql.connector will never work in a Bash console, because it's Python. In that console, you can try

python -c "import mysql.connector"

to see whether that works. If it does, then you need to make sure that your web app is configured to use that virtualenv. If it doesn't, then you need to pip install the mysql-connector package.