|
From: Robert X. <nne...@gm...> - 2009-08-12 22:40:05
|
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
|