Black Lives Matter. Please consider donating to Black Girls Code today.

Streaming with python


iam very new to plotly.
first made a few charts with static info.

now I try to stream data.
basicly its a demo from the web but it does not run
here is the terminal

File “”, line 33
print py.plot(fig, filename=‘basic-line’)
SyntaxError: invalid syntax
Error in sys.excepthook:
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/”, line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File “/usr/lib/python3/dist-packages/apport/”, line 5, in
from import Report
File “/usr/lib/python3/dist-packages/apport/”, line 30, in
import apport.fileutils
File “/usr/lib/python3/dist-packages/apport/”, line 23, in
from apport.packaging_impl import impl as packaging
File “/usr/lib/python3/dist-packages/apport/”, line 23, in
import apt
File “/usr/lib/python3/dist-packages/apt/”, line 23, in
import apt_pkg
ModuleNotFoundError: No module named ‘apt_pkg’

Original exception was:
File “”, line 33
print py.plot(fig, filename=‘basic-line’)
SyntaxError: invalid syntax

and her is the python code

import plotly.plotly as py
from plotly.graph_objs import Scatter, Layout, Figure
import time
#import readadc

#username = ‘your_plotly_username’
#api_key = ‘your_api_key’
#stream_token = ‘your_stream_token’

username = ‘twan’
api_key = ‘CcH91G08SAVl8tvQPAUL’
stream_token = ‘8jer495ad1’

py.sign_in(username, api_key)
#py.sign_in(username = ‘twan’, api_key= ‘6sIy2KqoFUbt9xb5ViFH’)

trace1 = Scatter(

layout = Layout(
title=‘Raspberry Pi Streaming Sensor Data’

fig = Figure(data=[trace1], layout=layout)

print py.plot(fig, filename=‘basic-line’)
#py.plot(fig, filename=‘basic-line’)

temperature sensor connected channel 0 of mcp3008

sensor_pin = 0

i = 0
stream = py.Stream(stream_token)

#the main sensor reading loop
while True:
# sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS)
sensor_data += 1
stream.write({‘x’: i, ‘y’: sensor_data})
i += 1
# delay between stream posts