467,910 Members | 1,650 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,910 developers. It's quick & easy.

Import PY file not included in py2exe executable

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?

Oct 4 '07 #1
  • viewed: 1985
Share:
2 Replies
wa********@comcast.net wrote:
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
Oct 4 '07 #2
On Thu, Oct 04, 2007 at 10:15:59AM -0700, wa********@comcast.net wrote:
... 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...

--

Florian Schmidt
Oct 4 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.