Forums

Can't use installed (using virtual env) scikit-learn in web app

Hi,

I am totally beginner with PythonAnywhere, so I guess I am missing something obvious… I did create a virtual environment for python 3.7, and installed scikit-learn :

$ mkvirtualenv my-virtualenv --python=python3.7
(my-virtualenv) $ pip install scikit-learn

I also created a web app on PythonAnywhere, using python 3.7 and linking it successfully to my virtual environment. But when I run my file flask_app.py, I got an error :

Traceback (most recent call last):
File "/home/Christophe/projet_7/flask_app.py", line 9, in <module>
import sklearn
ModuleNotFoundError: No module named 'sklearn'

Any idea of what I missed ?

Are you running the flask_app.py file from a bash console? If so, you'll need to activate your virtualenv first. That said, you normally don't need to run the Flask code from Bash -- you just set it up on the "Web" page. I can see that you did get the error you report in your website's error log once today, but that was almost two hours before your forum post.