[英]ImportError: No module named __main__ (Python 2.7 & Pickle)
So on my game I'm making, I'm trying to load the data files needed for the game, and when I load the file with pickle (The file has been loaded, I've double-checked that.) I get this error: 因此,在我正在制作的游戏中,我试图加载游戏所需的数据文件,并且当我用pickle加载文件时(文件已加载,我已经仔细检查过。)错误:
Traceback (most recent call last):
File "/Users/user/Downloads/Deeper-master/Deeper.py", line 257, in <module>
tutorialData = pickle.load(tutorialFile)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1075, in load_inst
klass = self.find_class(module, name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named __main__
I saw a question like this on Stack Overflow, but it's a little different than my situation, so sorry if this is a duplicate, I'm just trying to figure it out. 我在Stack Overflow上看到了这样的问题,但这与我的情况有些不同,所以很抱歉,如果这是重复的,我只是想弄清楚。
You can find my code here . 您可以在这里找到我的代码。 The main script is Deeper.py, just to save time.
主要脚本是Deeper.py,只是为了节省时间。
If you notice in your repo, you have a Deeper.pyc
and Deeper.py
. 如果您在回购中注意到,则有一个
Deeper.pyc
和Deeper.py
。 If I run Deeper.py
, it raises the same exception as yours. 如果我运行
Deeper.py
,它将引发与您相同的异常。 If I run Deeper.pyc
, it raises another exception: 如果我运行
Deeper.pyc
,它将引发另一个异常:
Traceback (most recent call last):
File "Deeper.py", line 7, in <module>
ToolbarTile = pygame.image.load("ToolbarTile.png")
pygame.error: Couldn't open Toolbar Tile.png
So, the code (bytecode, some previous version) references ToolbarTile.png
, but the exception is about Toolbar Tile.png
(with a space). 因此,代码(字节码,某些以前的版本)引用了
ToolbarTile.png
,但有关Toolbar Tile.png
(带空格)的例外。 So I changed the file name to account for that. 因此,我更改了文件名以解决此问题。
Now it raises: 现在它提出了:
Traceback (most recent call last):
File "Deeper.py", line 766, in <module>
else:
File "Deeper.py", line 394, in __init__
def displayCraft(self):
pygame.error: Couldn't open options.png
There's an Options.png
in your files, but it looks for options.png
(lower case) (even your new code in Deeper.py looks for that). 您的文件中有一个
Options.png
,但它会查找options.png
(小写)(即使您在Deeper.py中的新代码也会查找该文件)。 So I changed that. 所以我改变了。
Now it works, albeit with Deeper.pyc
so that must be why you thought: 现在可以使用,尽管与
Deeper.pyc
一起Deeper.pyc
所以这一定是您认为的原因:
(The file has been loaded, I've double-checked that.)
(文件已加载,我已经仔细检查过。)
Maybe delete the Deeper.pyc
and do a git-bisect to see when the bug was introduced (ps: check your toolbar.dat, does it seem okay to you? Also check the way you're using pickle.load. Maybe you should use rb
instead of r
?) 也许删除
Deeper.pyc
并执行git-bisect来查看何时引入该错误(ps:检查您的toolbar.dat,对您来说还好吗?还请检查您使用pickle.load的方式。也许您应该使用rb
代替r
?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.