✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

[wsgi:error] Dash was not successfully imported

Hi, Dash family.

I’m student for studying a visualization server

I want to use Dash on flask with apache.

So, I used flask with apache. It was success.

but, Using Dash has an error.

I tried several things including dash reinstallation, but it did not work.

Below is my .py , .wsgi file and error log.

please, give me a solution.

Thank you!

shs.py

import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html

import flask
import pandas as pd
import time
import os

server = flask.Flask(name)

df = pd.read_csv(‘https://raw.githubusercontent.com/plotly/datasets/master/hello-world-stock.csv’)

app = dash.Dash(name, server=server)

app.scripts.config.serve_locally = False
dcc._js_dist[0][‘external_url’] = ‘https://cdn.plot.ly/plotly-basic-latest.min.js

app.layout = html.Div([
html.H1(‘Stock Tickers’),
dcc.Dropdown(
id=‘my-dropdown’,
options=[
{‘label’: ‘Tesla’, ‘value’: ‘TSLA’},
{‘label’: ‘Apple’, ‘value’: ‘AAPL’},
{‘label’: ‘Coke’, ‘value’: ‘COKE’}
],
value=‘TSLA’
),
dcc.Graph(id=‘my-graph’)
], className=“container”)

@app.callback(Output(‘my-graph’, ‘figure’),
[Input(‘my-dropdown’, ‘value’)])

def update_graph(selected_dropdown_value):
dff = df[df[‘Stock’] == selected_dropdown_value]
return {
‘data’: [{
‘x’: dff.Date,
‘y’: dff.Close,
‘line’: {
‘width’: 3,
‘shape’: ‘spline’
}
}],
‘layout’: {
‘margin’: {
‘l’: 30,
‘r’: 20,
‘b’: 30,
‘t’: 20
}
}
}

if name == ‘main’:
app.run_server()

shs.wsgi

import sys, os

sys.path.insert(0, ‘/var/www/flask/’)

from shs import server as application

error log

[Wed Apr 03 10:08:06.785044 2019] [wsgi:error] [pid 12843:tid 139975872104192] Dash was not successfully imported. Make sure you don’t have a file named
[Wed Apr 03 10:08:06.785057 2019] [wsgi:error] [pid 12843:tid 139975872104192] ‘dash.py’ in your current directory.
[Wed Apr 03 10:08:06.785075 2019] [wsgi:error] [pid 12843:tid 139975872104192]
[Wed Apr 03 10:08:06.785140 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] mod_wsgi (pid=12843): Target WSGI script ‘/var/www/flask/shs.wsgi’ cannot be loaded as Python module.
[Wed Apr 03 10:08:06.785155 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] mod_wsgi (pid=12843): SystemExit exception raised by WSGI script ‘/var/www/flask/shs.wsgi’ ignored.
[Wed Apr 03 10:08:06.785289 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] Traceback (most recent call last):
[Wed Apr 03 10:08:06.785314 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/var/www/flask/shs.wsgi”, line 5, in
[Wed Apr 03 10:08:06.785316 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from shs import server as application
[Wed Apr 03 10:08:06.785320 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/var/www/flask/shs.py”, line 2, in
[Wed Apr 03 10:08:06.785325 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] import dash
[Wed Apr 03 10:08:06.785328 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/dash/init.py”, line 1, in
[Wed Apr 03 10:08:06.785330 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from .dash import Dash # noqa: F401
[Wed Apr 03 10:08:06.785332 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/dash/dash.py”, line 19, in
[Wed Apr 03 10:08:06.785334 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] import flask
[Wed Apr 03 10:08:06.785337 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/flask/init.py”, line 17, in
[Wed Apr 03 10:08:06.785338 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from werkzeug.exceptions import abort
[Wed Apr 03 10:08:06.785341 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/werkzeug/init.py”, line 233, in
[Wed Apr 03 10:08:06.785343 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] import(“werkzeug.exceptions”)
[Wed Apr 03 10:08:06.785345 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/werkzeug/exceptions.py”, line 73, in
[Wed Apr 03 10:08:06.785347 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from .wrappers import Response
[Wed Apr 03 10:08:06.785350 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/werkzeug/wrappers/init.py”, line 21, in
[Wed Apr 03 10:08:06.785351 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from .accept import AcceptMixin
[Wed Apr 03 10:08:06.785354 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/werkzeug/wrappers/accept.py”, line 1, in
[Wed Apr 03 10:08:06.785356 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from …datastructures import CharsetAccept
[Wed Apr 03 10:08:06.785358 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/werkzeug/datastructures.py”, line 14, in
[Wed Apr 03 10:08:06.785360 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] from copy import deepcopy
[Wed Apr 03 10:08:06.785363 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/var/www/flask/copy.py”, line 2, in
[Wed Apr 03 10:08:06.785364 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] import dash_core_components as dcc
[Wed Apr 03 10:08:06.785367 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] File “/usr/local/lib/python3.5/dist-packages/dash_core_components/init.py”, line 15, in
[Wed Apr 03 10:08:06.785368 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] _sys.exit(1)
[Wed Apr 03 10:08:06.785377 2019] [wsgi:error] [pid 12843:tid 139975872104192] [remote 127.0.0.1:41643] SystemExit: 1

Do you get the same issue when running $ python shs.py

Looks like it might be an issue with Apache reading in Python packages. Which Python installation are you using to run with?

If you’re not already I would recommend creating a new virtualenv and installing dash and also mod_wsgi-express, then run your app with mod_wsgi-express start-server shs.wsgi

You shouldn’t need to fiddle with sys.set_path then.

mod_wsgi-express is a vastly simpler way to Python apps than through defining your own apache conf file.

Is there a tutorial about WSGI server?