Issue 21050: Failure to import win32api (from pywin32) (original) (raw)
With python 3.4 and pywin32 version 218 it is only possible to import win32com or win32api when pywintypes has been imported before.
Here is part of a session with 'python -v':
import win32api Traceback (most recent call last): File "", line 1, in File "", line 2214, in _find_and_load File "", line 2203, in _find_and_load_unlocked File "", line 1191, in _load_unlocked File "", line 1161, in _load_backward_compatible File "", line 539, in _check_name_wrapper File "", line 1692, in load_module File "", line 321, in _call_with_frames_removed ImportError: DLL load failed: Das angegebene Modul wurde nicht gefunden. import pdb; pdb.pm() (321)_call_with_frames_removed() (Pdb) locals() {'kwds': {}, 'f': , 'args': ('win32api', 'C:\Python34\lib\site-packages\win32\win32api.pyd')} (Pdb) q import pywintypes
C:\Python34\lib\site-packages\win32\lib__pycache__\pywintypes.cpython-34.pyc matches C:\Python34\lib\site-packages\win32\lib\pywintypes.py
code object from 'C:\Python34\lib\site-packages\win32\lib\__pycache__\pywintypes.cpython-34.pyc'
C:\Python34\lib__pycache__\imp.cpython-34.pyc matches C:\Python34\lib\imp.py
code object from 'C:\Python34\lib\__pycache__\imp.cpython-34.pyc'
import 'imp' # <_frozen_importlib.SourceFileLoader object at 0x02F64AB0>
extension module loaded from 'C:\Python34\lib\site-packages\win32\_win32sysloader.pyd'
C:\Python34\lib__pycache__\datetime.cpython-34.pyc matches C:\Python34\lib\datetime.py
code object from 'C:\Python34\lib\__pycache__\datetime.cpython-34.pyc'
import 'datetime' # <_frozen_importlib.SourceFileLoader object at 0x02F70230> import 'pywintypes' # <_frozen_importlib.SourceFileLoader object at 0x02F64950>
import win32api
extension module loaded from 'C:\Python34\lib\site-packages\win32\win32api.pyd'
For those that don't read German, the exception says "The specified module could not be found".
Anyway, what looks suspicious to me is this line that gets imported by pywintypes:
extension module loaded from 'C:\Python34\lib\site-packages\win32\_win32sysloader.pyd'
That module's name suggests it might be critical. I also wonder what is going on with your sys.path as pywintypes is coming from site-packages\win32\lib\pywintypes.py while win32api is coming from site-packages\win32\win32api.pyd (notice how pywintypes is in some lib subidrectory and win32api is not). That suggests to me that something is mucking with sys.path somewhere to make this require the ordering.
It was most certainly an issue on my side, something with leftover files or directories from a previous installation. After cleaning everything up it works now. Sorry for the confusion.
(A personal remark: sometimes, the bdist_wininst uninstaller does not remove all directories that it has created - possibly because there are files leftover which the installer didn't create and so the uninstaller does not remove. This leaves directories on sys.path which have no init.py? files, but they can be imported as 'namespace module' although they no functionality. I don't find this useful...)