Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Robert Peters
3,728 PointsScript works in workspaces but not offline
I'm trying to update a little script that I started on workspaces, wanted to mess about offline for a while with it. It works perfectly on here, just one simple function, but on my Linux terminal or on the Cygwin terminal on Windows, i just keep getting a syntax error. Im a complete beginner so have NO idea what the problem could be!
Please could someone help?
Link to snapshot: https://w.trhou.se/ynvz8jpi6r
If it helps, my Python version is 3.5 so as far as I know up to date.
2 Answers
Christopher Shaw
Python Web Development Techdegree Graduate 58,248 PointsI suspect you are running python 2 as the default, even if you have installed python 3. I have found that the default python on Linux and Mac tends to be 2. (Sorry, I do not use windows)
To test, I copied and pasted your code into a file (err.py) on my Linux machine. If I ran python err.py, it produced the same error. If I ran python3 err.py, it worked correctly.
If you type python in the Linux terminal, it will will tell you the version. My default is 2.7.10. As I have both 2 and 3 installed, when I type python3, the version is. 3.4.3.
When you have a bit more experience, you should look at creating a virtual environment. This does look confusing at first, but you can create an environment with python3 as the default, and any packages you install with pip, are only in the environment, not at the system level. You can of course have multiple environments for different project requirements.
Robert Peters
3,728 PointsThanks yeah that was the problem, ill look into the virtual environments properly soon! I managed to get python on windows command line and powershell set up (withought a virt. env) thanks to the workspace video on here, but I do like to use Linux, just starting so not all that familiar with it but eventually I reckon ill make the switch for good. Thanks for the answer pal!
Robert Peters
3,728 PointsRobert Peters
3,728 Points3.5 on Linux anyway, not on Cygwin