[Instructions] Create executable using py2exe


10-07-2008 14:25:41

Build PythonOgre executable using py2exe:

I wrote a game, which gets initialization information from config files (not python scripts) in a config_folder in the main folder 'C:\PythonOgre\demos\MyGame'. So the directory structure for my game would be:

> MyGame
---> config_folder
------> config1.conf
------> config2.conf
---> mygame.py
---> lib_file1.py
---> lib_file2.py

I was able to successfully create executables for the game using py2exe. Just want to share with you guys the procedure, which does not seem to be described thoroughly anywhere.

1. You can't organize your modules into folders like './libs'. You must dump all scripts into your main folder, i.e. MyGame in my case. Main reason: Avoid changing sys path in your game.
2. You must be able to run your program thoroughly without any error (apparently).

1. Create file 'setup.py' in folder MyGame. The content is simple:
from distutils.core import setup
import py2exe


2. Install vcredist_x86.exe, Microsoft Visual C++ 2005 Redistributable Package (x86), downloadable from Microsoft website.

3. Search in your computer the following files: MSVCP80.dll and MSVCR80.dll. After you have done step 2, they must be somewhere in your computer. Copy them to folder MyGame.

4. Search in Ogre folders (I can't remember which one, to play safe, just search in all), at least look at C:\PythonOgre (or the respective installed folder of PythonOgre on your PC) and %Python25_folder%, the file: boost_python-vc80-mt-1_35.dll. Copy it to folder MyGame.

5. Try running from MS Command Prompt, in folder MyGame:
python setup.py py2exe
From now on, if you encounter any error message regarding dll files not found, try searching for them on your own PC, not google, then copy to folder MyGame.

6. The py2exe command in step 5 should have ended successfully by now. Now, all your executables are ready in MyGame\dist.

7. (for my own game) Copy config_folder into dist.

8. Copy plugins.cfg and resources.cfg to dist.

9. In dist, create folder 'plugins'. Copy all dll files from C:\PythonOgre\plugins to this folder.

10. In dist, open plugins.cfg, change 'PluginFolder=../../plugins' to 'PluginFolder=./plugins'

11. In dist, create folder Media. In folder Media, create folder 'Ogre' to store Ogre's resources, and folder 'MyGame' to store MyGame's resources. Copy all folders from C:\PythonOgre\demos\media into 'Ogre', and copy all your resource files to 'MyGame'

12. In dist, open resources.cfg. Change all paths of Bootstrap and General section from '../media' to 'Media/Ogre', and all paths of MyGame section to 'Media/MyGame'.

13. Try running mygame.exe several times. Whenever you encounter a problem, check out mygame.exe.log for the error message. If there is error regarding file not found, try searching it on your computer, and copy to folder 'dist' or 'dist\plugins'.

15. Done!!

Phew, that was a long first post. I hope some people would find this useful. Anybody with experience, please chip in when you find anything good to share.

Next, I'm going to try packaging the executables using Inno Setup.


14-07-2008 09:26:53


sounds a lot like the steps i follow for my project. However i read numerous posts on the internet saying that -regarding the VC8 runtimes- you can't always get away with just copying your files. So i have the inno setup installer run the vcredist_x86.exe file on the player's system.

Also, i don't copy the media files first, i just let inno setup grab them from my project's folder :)


14-07-2008 20:28:24

can you please put these instructions on the wiki?

http://wiki.python-ogre.org/index.php/E ... stribution