문제

This is the result when I attempt to run Python turtle graphics on my Mac. 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?

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. 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.

This happens because when you run the python interpreter interactively, it will add the current working directory to the front of sys.path automatically. (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.)

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).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top