2017-07-18 22 views
2

找不到參考「XXX」我試着畫一個五角星帶內置LIB烏龜。PyCharm:在「turtle.py」

環境:

  • 的Windows 10
  • 的Python 3.5
  • PyCharm社區版2017年1月5日

代碼:

import turtle 


turtle.fillcolor('red') 
turtle.begin_fill() 
while True: 
    turtle.forward(200) 
    turtle.right(144) 
    if abs(turtle.pos()) < 1: 
     break 
turtle.end_fill() 

的所有龜的方法,包括'fillcolor' 「begin_fill」,「前進」,「右」和「正」等,都是由PyCharm警告與伴隨着「找不到參考‘turtle.py’XXX'」,並自動完成這些方法失敗警告。但奇怪的是腳本可以按預期正常運行。

我SO尋找答案,還有一些相關的問題,但不一樣的,實際上是:

  1. 找不到參考「__init__.py」
  2. 未解決的參考'XXX'打印」

答案的全部,上述問題中,解決不了這個問題。

根據第一批的意見和答案,有的下面提供更多的信息:

  • 我幾乎相信我用龜爲Python 3.x的,因爲只有一個turtle.py文件在我的筆記本電腦,根據目錄 'C:\ Python35 \ Lib文件'。順便說一句,如果它仍然可能我用龜爲Python 2.x的,我怎麼能檢查這個信息,我怎麼可以更新默認目錄這個內置的lib?
  • 我幾乎相信我沒有使用的virtualenv,和我凸出的解釋是Python的3.5.2

(不幸的是,我仍然不能上傳圖片)

+0

你在python3編碼與python2烏龜。確保您有python3 – inspectorG4dget

+0

我幾乎相信我使用python3龜,因爲只有一個在我的下迪爾「C:\ Python35 \ Lib文件」 PC turtle.py。我會更新我的問題描述。 –

回答

1

的問題是在\ Lib文件\ turtle.py。

魔術變量所有的定義如下:

__all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions + 
      _tg_utilities + ['Terminator']) # + _math_functions) 

而且PyCharm不執行該代碼同時掃描包。因此PyCharm無法定義哪些功能可以在模塊級別使用。

所以你可以改變turtle.py:

# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions + 
#   _tg_utilities + ['Terminator']) # + _math_functions) 
__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back', 
      'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen', 
      'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput', 
      'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen', 
      'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 
      'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp', 
      'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd', 
      'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto', 
      'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease', 
      'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset', 
      'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx', 
      'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt', 
      'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor'] 

您也可以使用龜類:

T = turtle.Turtle() 
T.fillcolor('red') 
etc