Best of both worlds: python packaging for a game - python

I am currently trying to package a game made with python and pygame and I am running into some issues.
I am using py2exe to package and have looked up some question on here about it but I couldn't find a great solution. I want to end up with a folder, containing an exe, that I can compress and put online. Running the setup.py works fine except it puts all the dependencies into library.zip. This means that the program, when run, does not work.
I found that someone else was running into this issue and they ended using the "skip archive = true" option to solve it. And while, yes, that does work for me too I was hoping there was a method that would still let the program be run without trouble but wouldn't clutter the folder with countless files.
To be very precise the issue I'm running into with the library.zip is:
ImportError: MemoryLoadLibrary failed loading pygame\mixer.pyd
Which, if I understand it properly, means that the program can not reach/find the mixer module of Pygame.
Here is the setup script I am currently using (and that isn't working):
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = [('resources', ['resources/step.wav',
'resources/wind2.wav',
'resources/The Steppes.ogg',
'resources/warrior3-nosword-notassle.png',
'resources/warrior3-sword.png',
'resources/warrior2-blood1.png',
'resources/warrior2-blood2.png',
'resources/warrior2-blood3.png',
'resources/warrior2-blood4.png',
'resources/warrior3-up.png',
'resources/warrior3-kneel.png',
'resources/warrior3-kneel-nosword.png',
'resources/warrior2-blood2-kneel.png',
'resources/warrior2-blood3-kneel.png',
'resources/warrior2-blood4-kneel.png',
'resources/warrior3-death.png',
'resources/warrior3-offarm.png',
'resources/menu1.png',
'resources/plains3-top-nomount.png',
'resources/mountains.png',
'resources/plains5-bottom.png',
'resources/plains3-bottom.png',
'resources/cloud1.png',
'resources/warrior2-sword.png',
'resources/warrior2-hand.png',
'resources/blue-tassle1.png',
'resources/blue-tassle2.png',
'resources/blue-tassle3.png',
'resources/blue-tassle4.png'])]
setup(options = {'py2exe': {"bundle_files": 1}},
data_files = data_files,
console = [{'script': "steppes2.0.py"}],
zipfile = None
)

This code in your setup.py should do the trick of producing a single executable (you will still have to distribute msvc dlls separately)
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
setup(
options = {'py2exe': {'bundle_files': 1}},
console = [{'script': "myscript.py"}],
zipfile = None,
)

Related

unable to include module in py2exe setup script (python3)

I'm trying to create an exe of a script I wrote, but i'm unable do include a package i need, the package is hurry.filesize, but where ever I run setup.py I get an error "ImportError: hurry", It's escaping the dot and not reading the whole word, I've tried 'hurry\.filesize' and many other combinations and it doesn't read the whole name.
Here is the setup script:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
data_files = []
for files in os.listdir('./img/'):
f1 = './img/' + files
if os.path.isfile(f1): # skip directories
f2 = 'img', [f1]
data_files.append(f2)
setup(windows=[{'script': 'Artifactory_Spider.py', 'icon_resources': [(0, './img\\tachk.ico')]}],
data_files=data_files,
options={'py2exe': {'includes': ['patoolib', 'hurry.filesize'], 'bundle_files': 2, 'compressed': True, 'dist_dir': './Artifactory Spider'}},
zipfile=None,)
This is a bit late in coming, but I just hit exactly the same problem.
The solution which - worked for me - is to create an empty __init__.py file in the hurry folder.
e.g. C:\Python34\Lib\site-packages\hurry\__init__.py
Then cxfreeze will include the hurry.filesize module.

.exe made using py2exe not doing anything

I'm using Python 2.7.9 on Windows 7 x86
the file i'm trying to make into an executable has the following source code:
import Tkinter
root=Tkinter.Tk()
root.mainloop()
Yeah, not much, just an empty window.
The setup file is:
from distutils.core import setup
import py2exe, sys, os
sys.argv.append('py2exe')
s=raw_input("Name:")
s=s+".py"
setup(
options = {'py2exe': {'bundle_files': 1, 'compressed': True}},
windows = [{'script': s}],
zipfile = None,
)
When i run the exe, nothing happens, even when using cmd. I get no errors either, it just... does nothing.
I've always found cx_freeze easier to use on Windows
http://cx-freeze.sourceforge.net/

running a python script as administrator

i'm writing an installer using py2exe which needs to run in admin to have permission to perform various file operations. i've modified some sample code from the user_access_controls directory that comes with py2exe to create the setup file. creating/running the generated exe works fine when i run it on my own computer. however, when i try to run the exe on a computer that doesn't have python installed, i get an error saying that the import modules (shutil and os in this case) do not exist. it was my impression that py2exe automatically wraps all the file dependencies into the exe but i guess that this is not the case. py2exe does generate a zip file called library that contains all the python modules but apparently they are not used by the generated exe. basically my question is how do i get the imports to be included in the exe generated by py2exe. perhaps modification need to be made to my setup.py file - the code for this is as follows:
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
)
Try to set options={'py2exe': {'bundle_files': 1}}, and zipfile = None in setup section. Python will make single .exe file without dependencies. Example:
from distutils.core import setup
import py2exe
setup(
console=['watt.py'],
options={'py2exe': {'bundle_files': 1}},
zipfile = None
)
I rewrite your setup script for you. This will work
from distutils.core import setup
import py2exe
# The targets to build
# create a target that says nothing about UAC - On Python 2.6+, this
# should be identical to "asInvoker" below. However, for 2.5 and
# earlier it will force the app into compatibility mode (as no
# manifest will exist at all in the target.)
t1 = dict(script="findpath.py",
dest_base="findpath",
uac_info="requireAdministrator")
console = [t1]
# hack to make windows copies of them all too, but
# with '_w' on the tail of the executable.
windows = [{'script': "findpath.py",
'uac_info': "requireAdministrator",
},]
setup(
version = "0.5.0",
description = "py2exe user-access-control",
name = "py2exe samples",
# targets to build
windows = windows,
console = console,
#the options is what you fail to include it will instruct py2exe to include these modules explicitly
options={"py2exe":
{"includes": ["sip","os","shutil"]}
}
)

LoadLibrary(pythondll) failed error using py2exe tutorials

I'm trying to use py2exe and right now I'm just having trouble building the samples and tutorials that come with py2exe. I run setup.py and that goes fine but when I try to run the exe that is created I get the "LoadLibrary(pythondll) failed" error. I haven't moved the exe from the dist directory and I see that python27.dll is in that dist directory. Does anyone know what might be happening?
In case it matters I'm running 32 bit python 2.7 with the corresponding 32 bit python 2.7 py2exe on windows 7.
Thanks
The test.py file just contains
print "test"
Here's my setup.py based off what Kirk wrote:
from distutils.core import setup
import py2exe
import sys
from glob import glob
project_folder = r'C:\\Python27\\Lib\site-packages\\py2exe\\samples\\test\\'
data_files = [
("dlls", glob(project_folder + r'dlls\\*.dll'))
,("pyds", glob(project_folder + r'pyds\\*.pyd'))
]
options = { }
setup(
name='test'
,options = options
,zipfile = None
,data_files=data_files
,console=['test.py']
)
You'll want to specifically include the python27.dll file. If you're including multiple things, use glob and a data files array like below to get the best results with py2exe. For this example, create a Dll folder and put python27.dll in there.
from distutils.core import setup
import py2exe
import sys
from glob import glob
data_files = [
("Stuff", glob(r'C:\projectfolder\Stuff\*.*'))
,("dlls", glob(r'C:\projectfolder\dlls\*.dll'))
,("pyds", glob(r'C:\projectfolder\pyds\*.pyd'))
]
options = { }
setup(
name='ProjectName'
,options = options
,zipfile = None
,data_files=data_files
,console=['projectname.py']
)
I know this is a pretty old question, but I had a similar problem.
I had uninstalled python and py2exe 64 bit to replace it with the 32 bit version.
After I did this, I always got this error.
Later, I deleted my dist and build directories from my project, and the subsequent build worked.

Making exe using py2exe + sqlalchemy + mssql

I have a problem with making exe using py2exe. In my project i'm using sqlalchemy with mssql module.
My setup.py script looks like:
from distutils.core import setup
import py2exe
setup(
windows=[{"script" : "pyrmsutil.py"}],
options={"pyrmsutil" : {
"includes": ["sqlalchemy.dialects.mssql", "sqlalchemy"],
"packages": ["sqlalchemy.databases.mssql", "sqlalchemy.cresultproxy"]
}})
But when i'm starting procedure like:
python.exe setup.py py2exe
I'm receiving build log with following errors:
The following modules appear to be missing
['_scproxy', 'pkg_resources', 'sqlalchemy.cprocessors', 'sqlalchemy.cresultproxy']
And in "dist" folder i see my pyrmsutil.exe file, but when i'm running it nothing happens. I mean that executable file starts, but do nothing and ends immediately without any pyrmsutil.exe.log. It's very strange.
Can anybody help me with this error?
I know it's no an answer per se but have you tries pyInstaller? I used to use py2exe and found it tricky to get something truly distributable. pyInstaller requires a little more setup but the docs are good and the result seems better.
For solving this issue you could try searching for the mentioned dlls and placing them in the folder with the exe, or where you build it.
Looks like py2exe can't find sqlalchemy c extensions.
Why not just include the egg in the distribution, put sqlachemy in py2exe's excludes and load the egg on start?
I use this in the start script:
import sys
import path
import pkg_resources
APP_HOME = path.path(sys.executable).parent
SUPPORT = APP_HOME / 'support'
eggs = [egg for egg in SUPPORT.files('*.egg')]
reqs, errs = pkg_resources.working_set.find_plugins(
pkg_resources.Environment(eggs)
)
map(pkg_resources.working_set.add, reqs)
sys.path.extend(SUPPORT.files('*.egg'))
i use Jason Orendorff's path module (http://pypi.python.org/pypi/path.py) but you can easily wipe it out if you want.

Categories