|
From: Robert X. <nne...@gm...> - 2009-08-13 07:50:06
|
py2exe puts all the python files in a .zip file, and uses a special importer
to import modules contained in that zip. When materials.py uses __file__ to
search for the TGA files, it gets
"directory/library.zip/visual/materials.py", and since .zip files can't
actually be treated as directories by Python, it fails to find the files.
I've tested py2exe out on VPython. This one change is sufficient to allow
py2exe to produce a fully self-contained version of the Python program,
including the Python interpreter and all necessary libraries (visual, numpy,
core modules, etc.).
Robert
2009/8/12 Bruce Sherwood <Bru...@nc...>
> What is it about py2exe that changes the directory structure, to move the
> .tga files away from the visual directory? Where does it put them (and why)?
> In my ignorance of py2exe, this fix of rummaging around in upper directories
> seems odd.
>
> Bruce Sherwood
>
> Robert Xiao wrote:
>
> As some people on this list have already noticed, materials.py searches for
> the texture .tga files in its own directory, which causes problems with
> packagers like py2exe.
>
> My solution to this is the following patch to materials.py, to allow it to
> search a few levels up from its own directory for these files:
>
> --- site-packages/visual/materials.py
> +++ site-packages/visual/materials.py
> @@ -147,10 +147,19 @@
> image = image[::-1]
> return image
>
> -texturePath = os.path.split( __file__ )[0] + "/"
> -data = loadTGA(texturePath+"turbulence3") # the targa file is 512*512*3
> -tx_turb3 = raw_texture( data=reshape(data,(64,64,64,3)), interpolate=True,
> mipmap=False )
> -tx_wood = raw_texture( data=loadTGA(texturePath+"wood"), interpolate=True)
> +curdir = os.path.dirname( __file__ )
> +for uplevel in range(4):
> + try:
> + uppath = os.path.sep.join([os.path.pardir]*uplevel)
> + texturePath = os.path.normpath(os.path.join(curdir, uppath)) +
> os.path.sep
> + data = loadTGA(texturePath+"turbulence3") # the targa file is
> 512*512*3
> + tx_turb3 = raw_texture( data=reshape(data,(64,64,64,3)),
> interpolate=True, mipmap=False )
> + tx_wood = raw_texture( data=loadTGA(texturePath+"wood"),
> interpolate=True)
> + except IOError, OSError:
> + if uplevel == 3:
> + raise
> + continue
> + break
>
> def get_default_channels(data):
> dims = data.shape
>
> Now you can use a setup.py like the following for py2exe:
>
> ---8< code >8---
> #py2exe setup script
>
> from distutils.core import setup
> import py2exe
>
> # find visual's files
> import os.path as path
> from glob import glob
> import visual
>
> tgas = glob(path.join(path.dirname(visual.__file__), "*.tga"))
>
> setup(
> # The first three parameters are not required, if at least a
> # 'version' is given, then a versioninfo resource is built from
> # them and added to the executables.
> version = "1.0.0",
> description = "Example Application",
> name = "Example Application",
>
> # targets to build
> console = ["example.py"],
>
> zipfile = "library.zip",
> options={
> "py2exe":{
> "optimize": 2,
> # Exclude some libraries which are non-essential.
> # These are imported indirectly from numpy.
> "excludes": ["doctest", "pydoc", "urllib2"],
> "compressed": True,
> "bundle_files": 1,
> "ascii": True,
> }
> },
>
> # VPython data files
> data_files=[("",tgas)],
> )
> ---8< /code >8---
>
> In the above script, I excluded three libraries (doctest, pydoc, urllib2)
> as they were imported from numpy but are not necessary for the system to
> function. This decreases the size of the resulting bundle considerably.
>
> Robert
>
> ------------------------------
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>
> ------------------------------
>
> _______________________________________________
> Visualpython-users mailing lis...@li...://lists.sourceforge.net/lists/listinfo/visualpython-users
>
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Visualpython-users mailing list
> Vis...@li...
> https://lists.sourceforge.net/lists/listinfo/visualpython-users
>
>
|