简体   繁体   English

运行OSX 10.6的Mac上的Python Turtle图形出现故障

[英]Python turtle graphics malfunction on a Mac running OSX 10.6

This is the result when I attempt to run Python turtle graphics on my Mac. 这是我尝试在Mac上运行Python turtle图形时的结果。 Has anyone else seen this. 有没有其他人看到过这个。 Are there suggestions for fixing this problem. 是否有解决此问题的建议。 Thanks in advance! 提前致谢!

$ python
Python 2.6.1 (r261:67515, Aug  2 2010, 20:10:18) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import turtle
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk/turtle.py", line 114, in <module>
    from copy import deepcopy
  File "/Users/morrison/copy.py", line 3, in <module>
    Interface summary:
IndexError: list index out of range
>>> 

Is your current directory /Users/morrison/ when you run this? 运行此目录时,当前目录是/Users/morrison/吗?

If so, the problem is that the interpreter's current working directory is being used for looking up python modules at runtime in addition to the standard locations. 如果是这样,那么问题是除了标准位置之外,解释器的当前工作目录还用于在运行时查找python模块。 You have a file copy.py in this directory and it is being imported when the standard library copy module is what was intended by the turtle module. 您在此目录中有一个文件copy.py ,当标准库copy模块正是turtle模块想要的模块时,该文件将被导入。

This happens because when you run the python interpreter interactively, it will add the current working directory to the front of sys.path automatically. 发生这种情况是因为,当您以交互方式运行python解释器时,它将自动将当前工作目录添加到sys.path的前面。 (There's a likewise effect if you were trying to run a script in this dir from a different directory - the script's directory would be added to the front of sys.path .) (如果尝试从另一个目录在此目录中运行脚本,也会产生同样的效果-脚本的目录将被添加到sys.path 。)

The easiest way around this is to just rename copy.py to mycopy.py (and don't forget to remove copy.pyc in that dir). 解决此问题的最简单方法是将copy.py重命名为mycopy.py (并且不要忘记在该目录中删除copy.pyc )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM