开发者

Compiled python script returns WindowsError: [Error 3] after using py2exe [duplicate]

开发者 https://www.devze.com 2023-03-01 04:57 出处:网络
This question already has an answer here: Python, pygame, py2exe (1 answer) Closed last month. So I have been writing this game for a while now and finally have it finished. However due t
This question already has an answer here: Python, pygame, py2exe (1 answer) Closed last month.

So I have been writing this game for a while now and finally have it finished. However due to the fact that the game is meant for a class and I used libraries that my teacher isn't going to bother installing I need to make a single executable that will run independent of python and the games dependencies. I ran py2exe and it completed successfully however when I run the exe I get this error:

Traceback (most recent call last):
  File "main.pyw", line 1, in <module>
  File "zipextimporter.pyo", line 82, in load_module
  File "libs\__init__.pyo", line 3, in <module>
WindowsError: [Error 3] Th开发者_StackOverflow社区e system cannot find the path specified: 'C:\\Users\\matt\\workspace\\COS125\\src\\dist\\includes.zip\\libs/*.*'

I have figured out what the most likely cause of the error is. It most likely stems from the auto importer I have installed for each package. In the init.py files for my packages I use the following code so that a simple "from libs import *" will import all the files in the lib package. This will make it so that each file will be loaded as if I loaded each one as "from libs.module import *".

The code in the init file is as follows:

import os, sys
path = os.path.dirname(__file__)
dirList = os.listdir(path)
for mod in dirList:
    ext = os.path.splitext(mod)
    mod = mod[:-len(ext[1])]
    if (mod not in dir() and 
        mod != "__init__" and
        mod != "" and
        mod != "._"):
        exec("from " + mod + " import *")

Essentially what I am asking is if anyone else knows how to do this without resulting in that error after compiling?


I think I ran into a similar problem a couple years ago, and I solved it by getting rid of zip files in the distribution.

With py2exe options, try setting zipfile=None or maybe turn off compression and turn off bundling.

Note that creating a Windows exe that will run on all Windows OS's is a pain. I got good feedback on this from the py2exe list here and here.

0

精彩评论

暂无评论...
验证码 换一张
取 消