Forums

problem with flask app + virtualenv + own packages

Hello,

I'm trying without success to run a flask app with a virtualenv containing a module of mine. The setting is the following:

  • my app is situated at /home/myself/mysite/myapp
  • In the webapps page, both "Source code" and "Working directory" point to /home/myself/mysite/myapp
  • in /var/www/path_to_my_wsgi.py, project_home is set to /home/myself/mysite/myapp
  • I created a virtualenv, and provided it in the webapps page "virtualenv"
  • I have a package my_module, lying in my home, that I installed in the virtualenv. I can see that it is installed. If can activate the venv, I can import my_module
  • In my app, there is somewhere an import "from my_module import..."

But the when running the app, I get an error (in the logs), namely that my_module

2022-06-07 07:28:53,839: Error running WSGI application
2022-06-07 07:28:53,849: ModuleNotFoundError: No module named 'my_module'

It looks like, the WSGI app does not use the virtualenv. But on the other hand, if I add a print(sys.executable) in the path_to_my_wsgi.py and run it in a console, it displays the correct venv:

python -i /var/www/path_to_my_wsgi.py
/home/myself/.virtualenvs/venv/bin/python

So ... I have no clue, what is going wrong! Thanks for any idea!.

Have you reloaded your web app after making changes to it?

Well, I did "only" a "touch my_wsgi.py". I though that it would be enough, but apparently not. Now, If i use the button "reload the app" from the panel, it works! Thx!

Great! Glad you got it working.