Problem with PyYAML installing DASH

Hi All,

I’m trying to pip install dash and I’m getting this error message:

Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I’m running python 3.7 with pip 19.0.3. Can anyone help? I need to get this sorted quickly as I’ve got a demo to prepare.

Thanks in advance

Can you paste your exact command and full error message.

Hi Damian,

Here’s what I did.

pip install dash

Collecting dash

Collecting dash-html-components==1.0.0 (from dash)

Requirement already satisfied: Flask>=1.0.2 in /anaconda3/lib/python3.7/site-packages (from dash) (1.0.2)

Collecting PyYAML>=5.1.1 (from dash)

Collecting flask-compress (from dash)

Collecting dash-core-components==1.0.0 (from dash)

Collecting dash-renderer==1.0.0 (from dash)

Collecting dash-table==4.0.1 (from dash)

Collecting plotly (from dash)

Using cached https://files.pythonhosted.org/packages/ff/75/3982bac5076d0ce6d23103c03840fcaec90c533409f9d82c19f54512a38a/plotly-3.10.0-py2.py3-none-any.whl

Requirement already satisfied: itsdangerous>=0.24 in /anaconda3/lib/python3.7/site-packages (from Flask>=1.0.2->dash) (1.1.0)

Requirement already satisfied: Jinja2>=2.10 in /anaconda3/lib/python3.7/site-packages (from Flask>=1.0.2->dash) (2.10)

Requirement already satisfied: Werkzeug>=0.14 in /anaconda3/lib/python3.7/site-packages (from Flask>=1.0.2->dash) (0.14.1)

Requirement already satisfied: click>=5.1 in /anaconda3/lib/python3.7/site-packages (from Flask>=1.0.2->dash) (7.0)

Requirement already satisfied: decorator>=4.0.6 in /anaconda3/lib/python3.7/site-packages (from plotly->dash) (4.4.0)

Collecting retrying>=1.3.3 (from plotly->dash)

Requirement already satisfied: pytz in /anaconda3/lib/python3.7/site-packages (from plotly->dash) (2018.9)

Requirement already satisfied: requests in /anaconda3/lib/python3.7/site-packages (from plotly->dash) (2.21.0)

Requirement already satisfied: six in /anaconda3/lib/python3.7/site-packages (from plotly->dash) (1.12.0)

Requirement already satisfied: nbformat>=4.2 in /anaconda3/lib/python3.7/site-packages (from plotly->dash) (4.4.0)

Requirement already satisfied: MarkupSafe>=0.23 in /anaconda3/lib/python3.7/site-packages (from Jinja2>=2.10->Flask>=1.0.2->dash) (1.1.1)

Requirement already satisfied: idna<2.9,>=2.5 in /anaconda3/lib/python3.7/site-packages (from requests->plotly->dash) (2.8)

Requirement already satisfied: certifi>=2017.4.17 in /anaconda3/lib/python3.7/site-packages (from requests->plotly->dash) (2019.3.9)

Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /anaconda3/lib/python3.7/site-packages (from requests->plotly->dash) (3.0.4)

Requirement already satisfied: urllib3<1.25,>=1.21.1 in /anaconda3/lib/python3.7/site-packages (from requests->plotly->dash) (1.24.1)

Requirement already satisfied: traitlets>=4.1 in /anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly->dash) (4.3.2)

Requirement already satisfied: jsonschema!=2.5.0,>=2.4 in /anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly->dash) (3.0.1)

Requirement already satisfied: jupyter-core in /anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly->dash) (4.4.0)

Requirement already satisfied: ipython-genutils in /anaconda3/lib/python3.7/site-packages (from nbformat>=4.2->plotly->dash) (0.2.0)

Requirement already satisfied: attrs>=17.4.0 in /anaconda3/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2->plotly->dash) (19.1.0)

Requirement already satisfied: pyrsistent>=0.14.0 in /anaconda3/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2->plotly->dash) (0.14.11)

Requirement already satisfied: setuptools in /anaconda3/lib/python3.7/site-packages (from jsonschema!=2.5.0,>=2.4->nbformat>=4.2->plotly->dash) (40.8.0)

Installing collected packages: dash-html-components, PyYAML, flask-compress, dash-core-components, dash-renderer, dash-table, retrying, plotly, dash

Found existing installation: PyYAML 5.1

Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I guess this is implying that PyYAML was installed by something other than pip? Not sure how to fix it per se, but in order to get you running quickly, can you install dash (and whatever else you need for your demo) in a virtual env?

python -m venv venv
. venv/bin/activate
pip install dash
1 Like

I thought I may have to do that. Thanks.

It looks like pyyaml was installed via conda, you should update it via conda:

conda update pyyaml 

Then try installing Dash via Pip.

1 Like

I tried that, same error. I created a virtual env and installed dash there. But I have a new problem. How do I sort this?

Thanks

I created a virtual env and installed dash there. But I have a new problem. How do I sort this?

Thanks

Event was removed in Dash 0.36 https://github.com/plotly/dash/blob/master/dash/CHANGELOG.md#0360---2019-01-25

Use event properties instead, for example the n_clicks property instead of the click event

As well as dash.callback_context to know which input changed 📣 Dash Club - Dispatch #4 - Latest Dash Developments

Thanks for responding so promptly. As I am new to Dash your help has been very much appreciated. Another question about my Event issue. As seen in the code snippet a live graph for twitter sentiment. My question is how do I implement n_clicks here?

Happy to help :slight_smile:
You can use Input('graph_update', 'n_interval') for this

I should have really given the full code. Here it is along with my new error. Hopefully, this is final one.

import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly
import random
import plotly.graph_objs as go
from collections import deque
import sqlite3
import pandas as pd

app = dash.Dash(name)
app.layout = html.Div([
html.H2(‘Live Twitter Sentiment’),
dcc.Graph(id=‘live-graph’, animate=True),
dcc.Interval(id=‘graph-update’, interval=1 * 1000),
])

@app.callback(Output(‘live-graph’, ‘figure’),
[Input(‘graph_update’, ‘n_interval’)])

def update_graph_scatter():
try:
conn = sqlite3.connect(‘twitter2.db’)
c = conn.cursor()
df = pd.read_sql(“SELECT * FROM sentiment WHERE tweet LIKE ‘%wimbledon%’ ORDER BY unix DESC LIMIT 1000”, conn)
df.sort_values(‘unix’, inplace=True)
df[‘sentiment_smoothed’] = df[‘sentiment’].rolling(int(len(df)/5)).mean()
df.dropna(inplace=True)

    X = df.unix.values[-100:]
    Y = df.sentiment_smoothed.values[-100:]
    
    data_1 = plotly.graph_objs.Scatter(x = X,
                                       y = Y,
                                       name = 'Scatter',
                                       mode = 'line+markers')
    
    return {'data': [data_1], 'layout': go.Layout(xaxis = dict(range = [min(X), max(X)]),
                                                 yaxis = dict(range = [min(Y), max(Y)]),)}

except Exception as e:
    with open('errors.txt', 'a') as f:
        f.write(str(e))
        f.write('\n')

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

ugh we really need to fix that bug https://github.com/plotly/dash/issues/791

We’ve detected an error in the callback definition but this bug prevents us from telling you what it is!

I see two issues here:

  • be careful about _ and - in graph-update vs graph_update (I think this is the one throwing the broken error)
  • every input (or state but you don’t have state) needs a corresponding arg in your callback, even if you aren’t going to use it. So def update_graph_scatter(n):

Yes I do have def update_graph_scatter(n): after the callback or am I missing something else.

app = dash.Dash( name )
app.layout = html.Div([
html.H2(‘Live Twitter Sentiment’),
dcc.Graph(id=‘live-graph’, animate=True),
dcc.Interval(id=‘graph-update’, interval=1 * 1000),
])

@app.callback(Output(‘live-graph’, ‘figure’),
[Input(‘graph-update’, ‘interval’)])

def update_graph_scatter():
try:
conn = sqlite3.connect(‘twitter2.db’)
c = conn.cursor()
df = pd.read_sql(“SELECT * FROM sentiment WHERE tweet LIKE ‘%wimbledon%’ ORDER BY unix DESC LIMIT 1000”, conn)
df.sort_values(‘unix’, inplace=True)
df[‘sentiment_smoothed’] = df[‘sentiment’].rolling(int(len(df)/5)).mean()
df.dropna(inplace=True)

    X = df.unix.values[-100:]
    Y = df.sentiment_smoothed.values[-100:]
    
    data_1 = plotly.graph_objs.Scatter(x = X,
                                       y = Y,
                                       name = 'Scatter',
                                       mode = 'line+markers')
    
    return {'data': [data_1], 'layout': go.Layout(xaxis = dict(range = [min(X), max(X)]),
                                                 yaxis = dict(range = [min(Y), max(Y)]),)}

except Exception as e:
    with open('errors.txt', 'a') as f:
        f.write(str(e))
        f.write('\n')

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

I apologise for the formatting.

@jgriffi try upgrading to dash v1.0.2 📣 Dash 1.0.2 released - it should fix the “‘Div’ object has no attribute ‘keys’” problem and give you a more helpful error message about what needs fixing in the callback.

1 Like

I have the same issue. Stuck with dash 0.43,
pip install dash==1.1.1 results in:

Installing collected packages: PyYAML, dash-core-components, dash-html-components, dash-renderer, dash-table, dash
Found existing installation: PyYAML 3.13
Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

Error message was:

Cannot uninstall ‘PyYAML’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I fixed executing this in the conda prompt:
pip install --ignore-installed PyYAML==5.1.2

It installed PyYAML 5.1.2

And after that pip install dash==1.1.1 worked fine :slight_smile:

1 Like
three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online