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

Streaming with python

hi,

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 “stream_plotly.py”, 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/apport_python_hook.py”, line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File “/usr/lib/python3/dist-packages/apport/init.py”, line 5, in
from apport.report import Report
File “/usr/lib/python3/dist-packages/apport/report.py”, line 30, in
import apport.fileutils
File “/usr/lib/python3/dist-packages/apport/fileutils.py”, line 23, in
from apport.packaging_impl import impl as packaging
File “/usr/lib/python3/dist-packages/apport/packaging_impl.py”, line 23, in
import apt
File “/usr/lib/python3/dist-packages/apt/init.py”, line 23, in
import apt_pkg
ModuleNotFoundError: No module named ‘apt_pkg’

Original exception was:
File “stream_plotly.py”, 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(
x=[],
y=[],
stream=dict(
token=stream_token,
maxpoints=200
)
)

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
readadc.initialize()

i = 0
stream = py.Stream(stream_token)
stream.open()

#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
time.sleep(0.25)