On dom, 2009-05-03 at 02:39 -0700, TerabyteST wrote:
> Hello. I have my wx Python program that I want to compile, and it uses
> an image as logo. It is located in .\data\logo.jpg. I want to make a
> standalone .exe file that doesn't need any data folder to work (it
> doesn't even start if the data folder is not there). How can I do that?
Assuming you are using PyInstaller SVN trunk, you can try like this:
* Modify your spec file to add DATA files to your toc after analysis.
Basically, after the Analysis call, add a line like this:
a.data += [("full/path/tofile", "DATA", "output/path/file"), ...]
The first argument of the tuple is the full path to the data file; you
can either use an absolute path, or a path relative to the current
directory where you run Build.py. The third argument is the destination
path for the file (even if you're running one-file, think it as if it
was a one-dir distribution; so you probably want something like
"data/logo.jpg").
* You then need some code like this in your program:
datadir = "data"
if not hasattr(sys, "frozen"): # not packed
datadir = os.path.join(os.path.dirname(__file__), datadir)
elif "_MEIPASS2" in os.environ: # one-file temp's directory
datadir = os.path.join(os.environ["_MEIPASS2"], datadir)
else: # one-dir
datadir = os.path.join(os.path.dirname(sys.argv[0]), datadir)
Yes, I would like to eventaully expose this with a better API, but for
now it's better than nothing :)
Please, let me know if it works so that I can turn this into a tutorial
to put on the website.
Thanks!
--
Giovanni Bajo
Develer S.r.l.
http://www.develer.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"PyInstaller" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/PyInstaller?hl=en
-~----------~----~----~----~------~----~------~--~---