Enviro-Phat with Python 3


When I use a python command such as light.light or light.rgb Python 3 gives an Invalid Syntax error, highlighting the first “light”. Using Python 2 or Python from a terminal its OK.
Any suggestions? I am pretty new to Python


Curious. Which Python IDE are you running to edit Python 3 code?


Not quite sure what you are asking. But I start by using the Programming menu from the desktop, select Python 3. I just then type in from the command prompt. I have tried various other enviro hat commands with no problems.
As stated if I use Python 2 no problems.
I used your one line “curl…” to install the driver.


Trying to use it like so?


I see from your picture its python 3.4.2.
Mine is version 3.5.3

If I use your code and I put a ‘print’ command in front of the 2nd line and run it I get Invalid syntax with envirophat highlighted in red.

If I run exactly the same code in Python 2 its OK.

Is it something to do with my newer version of Python 3 ? Its come on your SD card with a Starter kit 2 weeks ago


print x is invalid in Python 3.x

You need to use, and get in the habit of using, print(x)


OK got it. But I was following the tutorial for the envirohat. I know its for python from the terminal but I was wanting to write some code in Python 3 and simply was not aware of the change.


Oh there are loads of tutorials still floating around that use print x, probably some of ours included! It’s one of the biggest gotchas in the transition from 2.x to 3.x. To be clear, there’s no ill will implied by my choice of phrasing :D

There are some other rather more subtle changes too. This page summarises them well, with examples too: http://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html