Import PY file not included in py2exe executable

Florian Schmidt schmidt_florian at
Thu Oct 4 20:04:32 CEST 2007

On Thu, Oct 04, 2007 at 10:15:59AM -0700, ward.david at wrote:
> ... because they are used for program configuration ...

not sure if i completely understood but i guess you do something like
    db_host = "mydbserver"
    db_user = "root"

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

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

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

    def read_config():
        execfile("", 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

More information about the Python-list mailing list