Import PY file not included in py2exe executable

W

ward.david

I am using py2exe to generate an executable so that I can deliver my
scripts as a EXE. I have a couple of file that are needed by the
program that I do not want to include in the EXE because they are used
for program configuration (similar to the way an INI file is used.)
These file may change per installation, so I may need to edit them.
Having them wrapped up in the EXE just won't work for my needs.

I've used the 'exclude' option to keep them from being included in the
EXE. I'm also using 'zipfile=None' so that all of the other pys are
included in the EXE. So, when I deliver the EXE all I should have in
my installation directory is:

MyProgram.exe
config1.py
config2.py
<misc Python pyds>

Is this possible? What is the setup.py configuration for this?
 
L

Larry Bates

I am using py2exe to generate an executable so that I can deliver my
scripts as a EXE. I have a couple of file that are needed by the
program that I do not want to include in the EXE because they are used
for program configuration (similar to the way an INI file is used.)
These file may change per installation, so I may need to edit them.
Having them wrapped up in the EXE just won't work for my needs.

I've used the 'exclude' option to keep them from being included in the
EXE. I'm also using 'zipfile=None' so that all of the other pys are
included in the EXE. So, when I deliver the EXE all I should have in
my installation directory is:

MyProgram.exe
config1.py
config2.py
<misc Python pyds>

Is this possible? What is the setup.py configuration for this?
I've found that using Inno Installer to package all the "other" stuff that I
need works EXTREMELY well. I almost always need .INI file, HISTORY.TXT,
README.TXT, icons, etc. Inno also allows me to ship a single setup.exe file
that can install my program, make registry entries (if needed), create
shortcuts, etc. The time I spend installing and learning Inno has paid for
itself many times over.

FYI, Larry
 
F

Florian Schmidt

... because they are used for program configuration ...

not sure if i completely understood but i guess you do something like
that:

my_config.py:
db_host = "mydbserver"
db_user = "root"
...

and in your program.py you have:
import my_config
...
DB.Connect(my_config.db_host, my_config.db_user...)

and your problem is that py2exe will package that my_config.py so that
"noone" can change it afterwards...

one possibility i often use is execfile:
same my_config as above, but:
program.py:
class config_class:
pass
my_config = config_class()
my_config.db_host = "localhost" # default config...

def read_config():
execfile("my_config.py", globals(), my_config.__dict__)
...
DB.Connect(my_config.db_host, my_config.db_user...)

so you can always call read_config() to re-read the configuration and have
all python features in that config file. (additionally you can catch
exceptions and check the config files' mtime if it has changed...)

that way py2exe won't care about your config file...

hope it helps...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top