Reputation: 131
Just learned python and I saw the turtle module, I tried using it with this Line (That was the instruction):
new_turtle = turtle.Turtle()
And it caused these errors:
Traceback (most recent call last):
File "D:/Python/Practices.py", line 2, in <module>
import turtle
File "D:\Python\lib\turtle.py", line 107, in <module>
import tkinter as TK
File "D:\Python\lib\tkinter\__init__.py", line 2091
print("Exception in Tkinter callback", file=sys.stderr)
^
SyntaxError: invalid syntax
Couldn't find answeres for specifficaly these errors. I want to ask why it happens here, but also a less specific questions: How come built in python functions cause errors? I also have errors when debugging with PyCharm, and the fact that built in functions and features cause errors kinda annoy me. Thanks a lot!
Upvotes: 1
Views: 99
Reputation: 33714
It seemed like you're using a Python 2 interpreter with a Python 3 site packages directory. Given the error points to the print statement in the tkinter library and only Python 2 interpreters will raise a SyntaxError
when encountering a print function.
You should go to the "Project Interpreter" settings and choose a correct interpreter and Python version (probably the one under D:\Python\
, which is for Python 3).
To simplify things, you can also create a venv as the project interpreter which helps you create a semi-isolated environment for your interpreter and all its dependencies. You can do so by clicking the "gear" icon next to Project Interpreter and choose "Add" then "Virtualenv Environment".
I also recommend you to not write files in Python's source directory (D:\Python
) as it can mess the PATH up.
Upvotes: 1