Using py2exe 0.9.2.0 under Python 3.4.1, on Windows 8 64-bit.
When running build_exe on a build script I migrated from Python 2.6.4, I get ValueError: pywintypes.loader is None
I have not found similar reports, so it may be a problem with the Python 3 environment I'm using, which we built here from source. It's working 100% on other fronts, however.
Full callstack:
D:\projects\thing1\python3\thing1\src\tools\tool_x>python -m py2exe.build_exe build.py
Traceback (most recent call last):
File "D:\projects\thing1\python3\thing1\output\python\lib\runpy.py", line 170, in _run_module_as_main
"main", mod_spec)
File "D:\projects\thing1\python3\thing1\output\python\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\build_exe.py", line 145, in <module>
main()
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\build_exe.py", line 141, in main
builder.analyze()
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\runtime.py", line 157, in analyze
self.mf.import_package(modname[:-2])
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 97, in import_package
self.safe_import_hook("%s.%s" % (name, modname))
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 365, in _scan_code
self._scan_code(c, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 365, in _scan_code
self._scan_code(c, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 365, in _scan_code
self._scan_code(c, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 365, in _scan_code
self._scan_code(c, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 320, in _find_and_load
self._scan_code(module.code, module)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 365, in _scan_code
self._scan_code(c, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 358, in _scan_code
self.safe_import_hook(name, mod, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 135, in safe_import_hook
self.import_hook(name, caller, fromlist, level)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 304, in _find_and_load
self._load_module(loader, name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 336, in _load_module
self._add_module(name, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\dllfinder.py", line 204, in _add_module
self.hook(mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\dllfinder.py", line 201, in hook
mth(self, mod)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\hooks.py", line 153, in hook_win32api
finder.import_hook("pywintypes")
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 117, in import_hook
module = self._gcd_import(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 267, in _gcd_import
return self._find_and_load(name)
File "D:\projects\thing1\python3\thing1\output\python\lib\site-packages\py2exe\mf3.py", line 297, in _find_and_load
loader = importlib.find_loader(name, path)
File "D:\projects\thing1\python3\thing1\output\python\lib\importlib__init__.py", line 70, in find_loader
raise ValueError('{}.loader is None'.format(name))
ValueError: pywintypes.loader is None</module>
Can you provide a minimal test-case that triggers this behaviour, please?
In stripping this test down I pinpointed the problem. My Python 3 (+pywin32) environment was missing this folder:
..\site-packages\win32com\gen_py\
Even though the only things to appear in there are auto-generated cache files, the fact this folder didn't exist on disk caused the above error. As soon as I created that empty directory py2exe ran with no issues.
Normally the gen_py folder is created by pywin32_postinstall.py when those extensions are installed, but in our environment there is no install process, and we just manually add that stuff to our sitecustomize.py. I'll have to add something to make that empty folder if it's not present.
Not sure if this info is useful but the ticket can be closed. Thank you.
I'm getting a similar error with a tool I'm developing. The tool uses wheezy.template to do some advanced string formatting, and py2exe (or rather, distutils) seems to be choking on it:
The file structure for wheezy.template is a bit odd - the 'wheezy' package is a directory with only a single folder in it, the 'template' package.
Last edit: Clay Sweetser 2014-08-29
Wait, don't close... I'm getting the same error, but apparently for different reasons because my gen_py folder exists. I'm not sure why I'm getting this error.
The problem with
ValueError: xxx.__loader__ is Noneis the following:py2exe's modulefinder doesn't (yet) support PEP420 implicit namespace packages; and when the modulefinder encounters one (or a directory that could be a namespace package) then this error is raised. A short term solution would be to print a more meaingful error message; however I'm working on adding support for these PEP420 namespace packages.
So, we should wait for the next py2exe release which will hopefully fix this...
If it is a namespace package problem then adding init.py somewhere should fix it. I tried doing that in any and all of the win32 folders with no luck. Could it have anything to do with the dynamic import stuff that pywintypes.py does? (source example: https://code.google.com/p/pythonxy/source/browse/src/python/pywin32/PLATLIB/win32/lib/pywintypes.py?repo=xy-27&r=f9ba065cb0e1dbbab6abc8e3b949ad5ccabad8b9)
My problem went away when I deleted an import of win32.client that I was doing during the setup script. (I had a build_helper.py thing that updated the version number on a Word Doc which used win32.Dispatch to talk to Word...). Since pywintypes was never imported, it never had the opportunity to muck up the sys.modules and confuse py2exe (I'm assuming...).
The next error I had did relate to Namespace modules... I had to add init.py to comtypes/gen because the gen folder was being picked up as a namespace module which later resulted in a key error when py2exe tried to get it's parent while trying to import it (again...I think...).
All I know is I got py2exe working again for me. Yay!