|
From: Bruce S. <Bru...@nc...> - 2009-08-13 02:29:53
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
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.<br>
<br>
Bruce Sherwood<br>
<br>
Robert Xiao wrote:
<blockquote
cite="mid:ef6...@ma..."
type="cite">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.<br>
<br>
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:<br>
<br>
--- site-packages/visual/materials.py<br>
+++ site-packages/visual/materials.py<br>
@@ -147,10 +147,19 @@<br>
image = image[::-1]<br>
return image<br>
<br>
-texturePath = os.path.split( __file__ )[0] + "/"<br>
-data = loadTGA(texturePath+"turbulence3") # the targa file is 512*512*3<br>
-tx_turb3 = raw_texture( data=reshape(data,(64,64,64,3)),
interpolate=True, mipmap=False )<br>
-tx_wood = raw_texture( data=loadTGA(texturePath+"wood"),
interpolate=True)<br>
+curdir = os.path.dirname( __file__ )<br>
+for uplevel in range(4):<br>
+ try:<br>
+ uppath = os.path.sep.join([os.path.pardir]*uplevel)<br>
+ texturePath = os.path.normpath(os.path.join(curdir, uppath)) +
os.path.sep<br>
+ data = loadTGA(texturePath+"turbulence3") # the targa file is
512*512*3<br>
+ tx_turb3 = raw_texture( data=reshape(data,(64,64,64,3)),
interpolate=True, mipmap=False )<br>
+ tx_wood = raw_texture( data=loadTGA(texturePath+"wood"),
interpolate=True)<br>
+ except IOError, OSError:<br>
+ if uplevel == 3:<br>
+ raise<br>
+ continue<br>
+ break<br>
<br>
def get_default_channels(data):<br>
dims = data.shape<br>
<br>
Now you can use a setup.py like the following for py2exe:<br>
<br>
---8< code >8---<br>
#py2exe setup script<br>
<br>
from distutils.core import setup<br>
import py2exe<br>
<br>
# find visual's files<br>
import os.path as path<br>
from glob import glob<br>
import visual<br>
<br>
tgas = glob(path.join(path.dirname(visual.__file__), "*.tga"))<br>
<br>
setup(<br>
# The first three parameters are not required, if at least a<br>
# 'version' is given, then a versioninfo resource is built from<br>
# them and added to the executables.<br>
version = "1.0.0",<br>
description = "Example Application",<br>
name = "Example Application",<br>
<br>
# targets to build<br>
console = ["example.py"],<br>
<br>
zipfile = "library.zip",<br>
options={<br>
"py2exe":{<br>
"optimize": 2,<br>
# Exclude some libraries which are non-essential.<br>
# These are imported indirectly from numpy.<br>
"excludes": ["doctest", "pydoc", "urllib2"],<br>
"compressed": True,<br>
"bundle_files": 1,<br>
"ascii": True,<br>
}<br>
},<br>
<br>
# VPython data files<br>
data_files=[("",tgas)],<br>
)<br>
---8< /code >8---<br>
<br>
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.<br>
<br>
Robert<br>
<pre wrap="">
<hr size="4" width="90%">
------------------------------------------------------------------------------
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. <a class="moz-txt-link-freetext" href="http://p.sf.net/sfu/bobj-july">http://p.sf.net/sfu/bobj-july</a></pre>
<pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Visualpython-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Vis...@li...">Vis...@li...</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/visualpython-users">https://lists.sourceforge.net/lists/listinfo/visualpython-users</a>
</pre>
</blockquote>
</body>
</html>
|