Forums

Import works on console with virtualenv activated, but not on web app

Hi,

I'm able to import the package dash from the console with my virtualenv active.

(env1) 13:28 ~ $ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dash
>>>

However, when I when launching my web app I get import error

2017-07-16 13:36:55,275: Error running WSGI application
2017-07-16 13:36:55,293: ImportError: No module named dash
2017-07-16 13:36:55,293:   File "/var/www/sherm4nlc_pythonanywhere_com_wsgi.py", line 120, in <module>
2017-07-16 13:36:55,293:     from analysis_dash import app as application
2017-07-16 13:36:55,293: 
2017-07-16 13:36:55,293:   File "/home/Sherm4nLC/hello_pdash/analysis_dash.py", line 2, in <module>
2017-07-16 13:36:55,293:     import dash

Virtualenv was added to the Web App config Dashboard >>>

Virtualenv: Use a virtualenv to get different versions of flask, django etc from our default system ones. More info here. You need to Reload your web app to activate it; NB - will do nothing if the virtualenv does not exist. /home/Sherm4nLC/env1

Any ideas?

are you still seeing problems? your site seems to be loading without errors just now...

Hi, thanks for reaching out. I'm still experiencing the same error, I left momentarily a dummy flask site running, but I reversed it so you can check the error. I could be wrong, but I think it's not my config, thanks in advance.

Now I see your current problem is

TypeError: 'Dash' object is not callable

I see other people suffering from the same problem here. Looking at the dash documentation on deployment I see that the "app" variable (the instance of a Dash object) is not actually a wsgi application. you need to use app.server as your wsgi application.

so, eg, in your wsgi file, something like this:

from analysis_dash import app
application = app.server

Excellent, I just needed to change that line on the WSGI file. Thanks a lot Harry

hooray! hope some other people see this and find it useful :)

So could someone post an example wsgi file suitable for dash. Thanks.

If you look in your wsgi.py file, there will be an application variable. You need to make that application variable what harry posted above.

from yourwebappmodule import app
application = app.server

Thanks, Conrad. Now its clear to me.

X

Thank you Glenn Jones. I did a pip upgrade and apparently I did have a version mismatch problem.

Glenn Jones: The only things I can think of might be that you haven't configured plotly (though I don't know if that's necessary) or you may have a version mismatch between plotly and dash.

Karl: Don't know if you can help with this but I'm still not quite there using Dash (plotly) ERROR LOG (says 'ERROR in app: Exception on / [GET]') Any ideas?

Hi, I also have the same problem. I have installed dash, set up the virtualenv and changed the wsgi to what is stated in the earlier post here. The instructions I followed are from the URL below, which is similar to the instructions here.

https://csyhuang.github.io/2018/06/24/set-up-dash-app-on-pythonanywhere/

I get the error message "ModuleNotFoundError: No module named 'dash'".

What can I do?

when I go to your website I get a working dash app?

Oh, that's amazing.

But how did the dash app get published on the website when it appears that my codes can't be run? When I tried to run my codes, I get the error message ModuleNotFoundError: No module named 'dash'. Does it mean that it is not necessary to run the codes for the dash app to be published?

Please pardon my ignorance as this is all very new to me.

How are you running it when you get the error? Are you sure that you have your virtualenv activated?

Hi Giles,

I opened up the .py file with the codes and clicked the "Run" button, and the error would occur.

My virtualenv has been set to /home/berniceliting/.virtualenvs/dashappenv and in the WSGI file, i have comment out

from flask_app import app as application

and replaced it with

from dashing_demo_app import app
application = app.server

Does the above activate the virtualenv? Have I missed out anything?

Thank you in advance for your help!

You can't run web apps on PythonAnywhere by running code in the console. The only way to run your web app is by configuring it on the "Web" page, and I see it done and working happily.

I see! Thanks for explaining, fjl