Forums

Module not found

Hi guys,

my flask app does not load an installed module. How can I fix that? Here is what I did:

1) Go to bash console 2) workon my-virtualenv 3) pip install Flask-Cors 4) Go to mysite/flask_app.py 5) Add from flask_cors import CORS, cross_origin 6) Run app 7) Getting result:

Traceback (most recent call last): File "/home/ehlersanalytics/mysite/flask_app.py", line 5, in <module> from flask_cors import CORS, cross_origin ModuleNotFoundError: No module named 'flask_cors'

Did I install it the right way? What can I do?

Cheers

M

Ok, a proper shebang did the trick.

If you're running stuff from a console, then yes, a shebang is the solution. It's worth noting, though, that running a Flask app in a console won't put it online -- you'll need to configure it on the "Web" tab.

Hi guys,

got a similar problem now that wasn't fixed by the shebang. I have installed keras and verified that it is really there in the virtualenv (see below). But when I import it I get the error below stating that the module was not found. What am I missing here?

Error Log

ModuleNotFoundError: No module named 'keras'

Shebang

1
#!/home/ehlersanalytics/.virtualenvs/my-virtualenv/bin/python3.6

Installed packages

16:36 ~ $ workon my-virtualenv
(my-virtualenv) 16:37 ~ $ pip freeze
-f /usr/share/pip-wheels
click==6.7
Flask==1.0.2
Flask-Cors==3.0.6
h5py==2.8.0
itsdangerous==0.24
Jinja2==2.10
Keras==2.2.2
Keras-Applications==1.0.4
Keras-Preprocessing==1.0.2
MarkupSafe==1.0
numpy==1.14.5
pandas==0.23.1
python-dateutil==2.7.3
pytz==2018.5
PyYAML==3.13
scikit-learn==0.19.1
scipy==1.1.0
six==1.11.0
sklearn==0.0
Werkzeug==0.14.1
(my-virtualenv) 16:37 ~ $

Cheers

M

[edit by admin: formatting]

You mention the error log, so I guess you're getting this error in a website's code...?

If so, you need to specify the virtualenv on the "Web" page (just under the "Code" section) rather than with a shebang.

Found the problem. Although it said keras is missing, it actually was missing the backend (tensorflow, theano, cntk). Once I installed theano (tensorflow was too big for my account), the problem went away.

great- thanks for letting us know!