Hi,
I am a newbie in python, and i am currently using py2exe in Windows and python 2.5 platform. The problem is, my python code is residing in several subdirectories (1 folder for images, 1 for other .py files etc). Now, I would like to use py2exe to create an exe file. However, after i run py2exe, the exe created can't run, as it states that it couldn't find the images, or the py files it's suppose to call. I used data_files to insert those files, and when i check, they are there. So i can't figure out what was wrong with the setup.py that i created.

Below are examples of the errors i got when i click open game.exe i created with py2exe:

error: Couldn't open C:\Documents and Settings\Administrator\Desktop\game\dist\game.exe\Data\loading_splash.jpg
WindowsError: [Error 3] The system cannot find the path specified: 'C:\\Documents and Settings\\Administrator\\Desktop\\game\\dist\\game.exe\\lib/*.*'

And within my setup.py, i got this:

setup(options = {"py2exe": {"optimize": 2, "bundle_files": 1}},
zipfile=None,
windows=["game.py"],
data_files=[("Data",glob.glob("Data/*.*")),
....................
("lib/MygameData",glob.glob("lib/MygameData\\*.*")),
....................

Anybody got any idea where i go wrong? Thanks in advance.

I've tried. But when i clicked on the exe file after it has compiled, it can't running. The thing is, when i run the python files without compiling, everything works fine. I think my problem is I did not know how to properly compile multiple subdirectories using py2exe as I've never done it before.

which GUI do you use? Gpy2exe should wake fine. Do you use setup.py?

Need clarification to help

Here's a snippet of a setup.py that I've used before to grab things that were not in the same directory...

setup(
  zipfile = None,
    # We use os.path.join for portability
    package_dir = {'': os.path.join('..', 'Common')},
    py_modules = ['mylog', 'IPVerify', 'logfile', 'remoteCmd', 'rd_num_gen', 'crc32'],
	windows = [
		{
			"script": "my_program.py",
			"icon_resources": [(1, "my.ico")],
			"other_resources": [(24,1,manifest)]
		}
	],
)

NOTE: The py_modules were .py scripts that were in the Common directory

I can't guarantee that this will work for images, but it will definitely work for modules.

evstevemd,
I've tried using gpy2exe before, but how can i include other .py files using its GUI? And yes, currently, I am trying to use setup.py, but I am a newbie at python, so i would appreciate any suggestions. Thanks.

jlm699,
I'm not sure how to include those other .py files. Currently, I have created a lib folder to store all the .py files i needed to run (1 py file per game). The flow is something like this GameFolder->lib->game1.py The main file would be in Gamefolder, and it would get those other games from the lib folder. I've tried this, but it py2exe doesn't seem to work:

setup(
    zipfile=None,
    package_dir = {' ': 'lib'},
    py_modules = ['game2'],
    windows = [{
        "script": "game.py",
        }
               ],
    )
)

Any ideas? Thanks.

I think i found out where the problem is. It seems that py2exe would not be able to compile a module if it was not in the code, ie import game1.....

So, is there any way to code in setup.py to ask it to include those modules that are not in the main code?

Thanks

Sometimes you can simply do import <module> in the setup.py script as a work around; however this does not work in all cases.

Is modules and packages the same as plugins? Cos what I am doing now is creating other .py files as plugins. How can I let the setup.py knows that it is suppose to get those other py files and images as plugins? If i do import <module> in the setup.py file, I'm afraid that it won't be able to import the images that comes with the modules.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.