Forums

New Flask app can't find my installed module

Hi, I have a module called 'vsearch' which I installed from console using 'python3 -m pip install vsearch-1.0.tar.gz --user'. The console message said that it 'Successfully built vsearch' and referenced folder './.local/lib/python3.5/site-packages'.

However, when I try to import the vsearch module, I get 'ModuleNotFoundError: No module named 'vsearch''. I know this is a common issue, but I have read the Forums and not found a solution. I am using the default Flask setup (not the manual virtualenv setup), and the code runs fine if I remove the offending import. It can also find the import and run correctly if I directly put the vsearch.py code in the /mysite folder.

So: why can't it find my installed module? And, is the virtualenv setup required in order to install your own modules? (The tutorial I am following did not mention this.) Thanks!

It seems like this relates to a mismatch between the Python version running my app (3.6) and the location where pip stored my module (which has python 3.5 in the path name). I re-installed the module using pip3.6, and now it finds the module correctly.

So that short-term problem seems to be fixed, but how do you do deal effectively with modules and dependencies when deploying to PythonAnywhere. With a real app, with multiple modules to deploy to the correct folder that matches the Python version, how do you do that efficiently and accurately?

Have a look at the pip docs for requirements files.

Hello.

I have a slightly similar issue apart from the fact that my Flask app and the module I installed (googleads) are both of the same version (Python 3.6).

The module is called googleads and AFAIK it is located in the /home/giancampo/.local/lib/python3.6/site-packages directory.

I'm sure I'm missing something on this, as usual :) Thanks in advance!

@giancampo -- what kind of error do you see in the error log? (You should read them from the bottom, where the most recent errors are.)

Well it seems now it's working, don't know frankly why.

FWIW the error messages I see are the following:

2021-07-04 14:45:46,631: Error running WSGI application 2021-07-04 14:45:46,643: NameError: name 'sleep' is not defined 2021-07-04 14:45:46,643: File "/usr/lib/python3.6/site-packages/flask/app.py", line 2463, in call 2021-07-04 14:45:46,643: return self.wsgi_app(environ, start_response) 2021-07-04 14:45:46,643: 2021-07-04 14:45:46,643: File "/usr/lib/python3.6/site-packages/flask/app.py", line 2449, in wsgi_app 2021-07-04 14:45:46,643: response = self.handle_exception(e) 2021-07-04 14:45:46,643: 2021-07-04 14:45:46,643: File "/usr/lib/python3.6/site-packages/flask/app.py", line 1866, in handle_exception 2021-07-04 14:45:46,644: reraise(exc_type, exc_value, tb) 2021-07-04 14:45:46,644: 2021-07-04 14:45:46,644: File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise 2021-07-04 14:45:46,644: raise value 2021-07-04 14:45:46,644: 2021-07-04 14:45:46,644: File "/usr/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app 2021-07-04 14:45:46,644: response = self.full_dispatch_request() 2021-07-04 14:45:46,644: 2021-07-04 14:45:46,644: File "/usr/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request 2021-07-04 14:45:46,645: rv = self.handle_user_exception(e) 2021-07-04 14:45:46,645: 2021-07-04 14:45:46,645: File "/usr/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception 2021-07-04 14:45:46,645: reraise(exc_type, exc_value, tb) 2021-07-04 14:45:46,645: 2021-07-04 14:45:46,645: File "/usr/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise 2021-07-04 14:45:46,645: raise value 2021-07-04 14:45:46,645: 2021-07-04 14:45:46,645: File "/usr/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request 2021-07-04 14:45:46,646: rv = self.dispatch_request() 2021-07-04 14:45:46,646: 2021-07-04 14:45:46,646: File "/usr/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request 2021-07-04 14:45:46,646: return self.view_functionsrule.endpoint 2021-07-04 14:45:46,646: 2021-07-04 14:45:46,646: File "/home/giancampo/mysite/flask_app.py", line 65, in script_page 2021-07-04 14:45:46,646: </form>

Please tell me if it's just spam and I will delete some rows above. Thanks.

Here's your problem: NameError: name 'sleep' is not defined. You are using a variable that it not defined. Check the traceback and your code to see where you're using that variable and work out why it's not defined.