py2exe and dynamic modules

Uwe C. Schroeder uwe at oss4u.com
Mon Jun 9 17:37:10 EDT 2003


well, not for me

my code looks like

<in some class>
        sys.path.append('c:\\documents and settings\\ucs\\ibcache\\modules')

< in some other class>

        def loadModule(self,_pref):
            _mod=__import__(_pref)
            m=getattr(_mod,_pref)
            self._modules[_pref]=m(self,self._perspective)
        

The modules are all the same: filename == classname inside.
So file xxx.py contains a class xxx
This code works fine without py2exe
With it it fails
File "imputil.pyc", line 106, in _import_hook
ImportError: No module name wecgla

(wecgla is actually the name and _pref in the above sample has that value)
My sys.path is set correctly ('','C:\\distdirectoy','c:\\documents and
settings\\ucs\\ibcache\\modules')

so something is different to your example.

BTW: your example doesn't work either.
Can it be py2exe import can't handle spaces in filenames ???

my test is

import sys
sys.path.append('c:\\documents and settings\\ucs\\ibcache\\modules')
try:
        __import__('wecgla')
except:
        raise

print 'OK'


Compiled with py2exe using:

from distutils.core import setup
import py2exe

setup(name="Test",
      scripts=['imptest.py'],
      )

and on the command line

python impsetup.py py2exe


any ideas ?
this is python 2.2.1 on win2k



Peter Hansen wrote:

> "Uwe C. Schroeder" wrote:
>> 
>> Peter Hansen wrote:
>> 
>> > Run imptest.exe from a directory other than c:/temp:
>> >
>> > "test OK" results.
>> >
>> > Looks like it works...  (I'm doing this test first... what did I do
>> > wrong this time?  :-)
>> 
>> :-)) You knew the path up front. But I'll probably do just that and
>> :install
>> the modules in a fixed path, although I don't really like it. But I guess
>> it's easier than fiddling around with the  py2exe import stuff.
> 
> Don't make it so hard on yourself!  Here's version two, without a
> hardcoded path:
> 
> import sys
> sys.path.append(sys.argv[1])
> filename = sys.argv[2]
> try:
>     mod = __import__(filename)
>     print mod.test()
> except:
>     print 'test failed!'
> 
> 
> Still works... ;-)
> 
> -Peter

-- 
        UC

--
Open Source Solutions 4U, LLC   2570 Fleetwood Drive
Phone:  +1 650 872 2425         San Bruno, CA 94066
Cell:   +1 650 302 2405         United States
Fax:    +1 650 872 2417




More information about the Python-list mailing list