Forums

Module error

I am getting this error:

Traceback (most recent call last): File "/home/BOTcommander/Customer_portal/app.py", line 12, in <module> from flask_mysqldb import MySQL ModuleNotFoundError: No module named 'flask_mysqldb'"

even though I have this module installed...

Do you run your code with the python version or in the virtual environment that you installed the module for?

I run my app.py file

Make sure that you are running your web app using the virtualenv/version of Python where you installed the module. If you're not using a virtualenv, pip installs into Python 2.7 and pip36 installs into Python 3.6 etc.

Yes it's same version 3.8

Your web app uses a virtualenv. Did you install the module into the virtualenv?

Yes I installed it in that virtual env with pip3.8 install. When I run 'pip3.8 list' all the needed packages are there including this one.

Are you sure that is the current error, then? The latest errors are at the bottom of the error log.

My website seems to work now. Not sure why i get that error when i just run the app.py file. Thank you.

It sounds like when you're running your app.py file directly, you're not using the virtualenv. Specifying a virtualenv on the "Web" page only means that when a request comes in to your site, your code will be run using that virtualenv. If you're running your code anywhere else -- from a Bash console, from the editor, or in some other way -- then you'll need to tell it to use the virtualenv.

However, if you've set everything up on the "Web" page so that the virtualenv is used there, you normally don't need to do anything else -- because the code is automatically run when a request comes in to your site, there's no need to run it from the editor or a console.

Im getting this error: ERROR: Package 'fxcmpy' requires a different Python: 2.7.12 not in '>=3.4' Anyone may give me a hand

If your virtualenv is activated when you get that error, you have created it to use Python 2.7. You can specify the Python version when creating a virtualenv using the --python flag, like this:

mkvirtualenv myvirtualenv --python=python3.8

So you should delete the 2.7 one that you have created, and create a new one using a more recent Python version.

Thank you for your help!

No problem!