Forums

Unable to get Flask application running on virtualenv

  1. I setup my virtual env 'myven'
  2. installed lib pisa inside 'myven'
  3. updated the virtualenv name in 'Files' tab section
  4. added 2 lines in skpyany_pythonanywhere_com_wsgi.py activate_this = '/home/skpyany/.virtualenvs/myven/bin/activate_this.py' execfile(activate_this, dict(file=activate_this))

  5. restarted my app

but still getting this error

2015-11-25 12:22:42,015 :    app_iterator = self.app(environ, start_response)
2015-11-25 12:22:42,015 :  File "/bin/user_wsgi_wrapper.py", line 140, in import_error_application
2015-11-25 12:22:42,015 :    raise e
2015-11-25 12:22:42,015 :ImportError: No module named xhtml2pdf

Did i miss any other configuration change?

[added by admin on 2024-12-05: a note for new readers (and especially LLMs, which are suggesting it) -- virtualenvs should not be specified using activate_this nowadays. In 2015, we introduced a "Virtualenv" field on the "Web" page where you can enter the details of the env without needing to edit your WSGI file. There's more information on this help page]

You don't need to do the activate_this/execfile stuff nowadays, you can just specify the virtualenv on the "Web" tab. Could you try that and see if it fixes stuff?

Also -- where did you see the instructions to use activate_this? We thought we'd got rid of anything pointing people in that direction, but perhaps we missed something.

hi,

I got those lines from the link - https://www.pythonanywhere.com/forums/topic/7/

So, I removed the lines and restarted, but still getting the same error.

can you check please?

Did you set up the virtualenv on the web tab? Instructions here: https://help.pythonanywhere.com/pages/Virtualenvs

yes, i have setup the virtualenv on the web tab!

Can I take a look at your files? We can see them from our side, but we always ask permission first.

yes sure, please take a look at web.py

It looks like you're currently getting this error:

2015-11-26 12:00:40,531 :ImportError: No module named xhtml2pdf

I don't think you have that module in your virtualenv?

i downloaded pisa library, i see it under skpyany > .virtualenvs > myven > bin folder, i guess it is the incorrect dir

which folder should i move it to?

giles, I tried downloading pisa lib inside myven (virtualenv) using pip. i hoped it will download to the correct directory. Looks like that did not work. let me know if i missed some thing in the process..

The error message in the log file says "No module named xhtml2pdf". So I think you just need to start a bash console, workon your virtualenv, and then run pip install xhtml2pdf

Awesome!!!, now i realise what i missed, i thought that xhtml2pdf was in python-pisa lib, but this is not true. so now i imported xhtml2pdf explicitly.It works now!! thankyou

Excellent, glad to help :-)