PyCharm and turtle

Question:

I have a problem with PyCharm. I start learning python with PyCharm and I want write some with turtle package. When i try execute this code

import turtle

bob = turtle.Turtle()

I have that message:

"C:Program FilesPython36python.exe" C:/Users/Ptr/Desktop/python/Proj_1/Gui.py
Traceback (most recent call last):
  File "C:/Users/Ptr/Desktop/python/Proj_1/Gui.py", line 1, in <module>
    import turtle
  File "C:Program FilesPython36libturtle.py", line 107, in <module>
    import tkinter as TK
  File "C:UsersPtrDesktoppythontkinter.py", line 3, in <module>
    okno = tkinter.Tk()
AttributeError: module 'tkinter' has no attribute 'Tk'

Process finished with exit code 1 

When I try execute that code using IDLE all works.
In PyCharm I try install turtle in project:

Python>Project Interpreter

but all time I have same error:

Collecting turtle
  Using cached turtle-0.0.2.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:UsersPtrAppDataLocalTemppycharm-packagingturtlesetup.py", line 40
        except ValueError, ve:
        except ValueError, ve:
                         ^
    SyntaxError: invalid syntax

    ----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:UsersPtrAppDataLocalTemppycharm-packagingturtle
  enter code here
Asked By: Incl

||

Answers:

You don’t pip turtle. Turtle is a built-in python package.
You just say import turtle.

Answered By: ds_secret

A couple of things to note for those running into this at a later time:

  • tkinter must be installed on your machine. There is a python2.x and
    python3.x version. It must match your version of python. For example,
    In Ubuntu, I am running python3.6, and had to run apt-get install
    python3.6-tk
  • Pycharm allows you to pick interpreters. It is possible to be running
    a different interpreter in IDLE than in PyCharm, making the mismatch
    of python and tkinter versions potentially confusing. This is further
    complicated potentially by virtual environments. Be certain your
    python version and you tkinter versions match.
  • You can not have modules in your import path of the name tkinter.py or turtle.py
  • As mentioned by ds_secret, turtle comes with python, no need to
    install it separately.
Answered By: SteveJ
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.