Forums

Unable to Import dash

Hi,

I am trying to run the following code;

import dash
from dash import dcc
from dash import html
from dash.dependencies import Output, Input
import dash_bootstrap_components as dbc
import plotly.graph_objects as gp
import numpy as np
import pandas as pd
#Data

df_01=pd.read_csv('pyramid.csv')

app= dash.Dash((__name__),external_stylesheets=[dbc.themes.FLATLY],
        meta_tags=[{'name': 'viewport',
                       'content': 'width=device-width, initial-scale=1.0'}]

 )

#Layout

app.layout = dbc.Container([ 
:::python

I do not use a virtualenv because after loading dash and pandas my diskspace is already full. So I use the normal enviroment with the dash in the batteries. Yet I recieve following error if I run this code in pythonanywhere:

Traceback (most recent call last):
 File "/home/lovitas/pyAny/bootapp_clean.py", line 2, in <module>
    from dash import dcc
ImportError: cannot import name 'dcc' from 'dash' (/usr/local/lib/python3.9/site-packages/dash/__init__.py)

On my local instance this is error does not occur. Since I am a total beginner any help would be appreciated!

It sounds like your code is written for a different version of Dash than the one that we have pre-installed in our batteries included -- probably a newer one. This Stack Overflow post is probably a good starting point if you want to adjust the code to use the older version. Alternatively, you might want to upgrade the account to get more disk space -- then you can install a more recent version of Dash.

Is it really not possible to install dash and pandas in 500mb ? I thought this should be possible. And dcc is the dash core components which should be avalible in older dash versions as well. Is this really the problem ?

If you check the Stack Overflow post, you'll see that while older versions of Dash did have DCC, it was imported differently.

An alternative to what I suggested before might be to not install pandas -- we already have it installed, so perhaps you could just use the older version for that rather than Dash.

I think the problem is on your side. The default dash version in your python environment is old. In the bash console putade the dash version: pip install dash --upgrade

You need to change system image to newer to have default versions upgraded. See https://help.pythonanywhere.com/pages/ChangingSystemImage