Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import win32api fails after pip install pywin32 (ImportError: DLL load failed: The specified module could not be found) #1399

Open
theonewolf opened this issue Aug 29, 2019 · 11 comments

Comments

@theonewolf
Copy link

theonewolf commented Aug 29, 2019

Expected behavior and actual behavior.

Expected import win32api to work without any exception.

Steps to reproduce the problem.

Below I am working in a virtualenv; however, this same problem occurs when I install not inside a venv (I just solved it for my system, so it's easier to illustrate inside a venv now).

pip install pywin32
python -c "import win32api"

With more verbosity, my steps look like:

(pywin32test) C:\Users\WolfgangRichter\Desktop>pip install pywin32
Collecting pywin32
  Using cached https://files.pythonhosted.org/packages/a3/8a/eada1e7990202cd27e58eca2a278c344fef190759bbdc8f8f0eb6abeca9c/pywin32-224-cp37-cp37m-win_amd64.whl
Installing collected packages: pywin32
Successfully installed pywin32-224


(pywin32test) C:\Users\WolfgangRichter\Desktop>python -c "import win32api"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.

Version of Python and pywin32

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:13:57) [MSC v.1916 64 bit (AMD64)] on win32

pywin32-224-cp37-cp37m-win_amd64.whl

@theonewolf
Copy link
Author

theonewolf commented Aug 29, 2019

I was able to resolve this by copying two DLLs:

(pywin32test) C:\Users\WolfgangRichter\Desktop>copy C:\Users\WolfgangRichter\Desktop\pywin32test\Lib\site-packages\pywin32_system32\pythoncom37.dll C:\Users\WolfgangRichter\Desktop\pywin32test\Lib\site-packages\win32\
        1 file(s) copied.

(pywin32test) C:\Users\WolfgangRichter\Desktop>copy C:\Users\WolfgangRichter\Desktop\pywin32test\Lib\site-packages\pywin32_system32\pywintypes37.dll C:\Users\WolfgangRichter\Desktop\pywin32test\Lib\site-packages\win32\
        1 file(s) copied.

(pywin32test) C:\Users\WolfgangRichter\Desktop>python -c "import win32api"

(pywin32test) C:\Users\WolfgangRichter\Desktop>

But, ideally, this is not required on a fresh install.

@thopiekar
Copy link
Contributor

Hello @theonewolf,

could you be so kind and run Python in your venv again and run the following lines?

import os
os.environ["PATH"]

Normally our .pth file within the site-packages directory should ensure that the .dll files can be found. However, due to your venv setup, it seems that something is mixed up there.

Thanks!

@mhammond
Copy link
Owner

Is it possible you have either a pythoncomXX.dll or pywintypesXX.dll in your system32 directory?

@kedakedaxia
Copy link

I have the same problem. Have you solved it?

@azoellner
Copy link

I had the same problem, but with version 225. Version 224, on the other hand, worked just fine for me.

I was able to fix this by removing the files pythoncom27.dll, pythoncomloader27.dll and pywintypes27.dll from C:\Windows\SysWOW64. They seemed to be quite old (2016-01-11 from 22:44 to 22:51), possibly from an earlier installation of the package (and not via pip?).
I could find the current versions of the DLLs in C:\Python27\lib\site-packages\pywin32_system32, which indeed is listed as the last entry of python -c "import os; print os.environ['PATH']".
So, thanks for your tips, everyone.

Possibly this issue is related to the issues #1406 and #1409.

@Jeff17Robbins
Copy link

Jeff17Robbins commented Sep 27, 2019

I just installed 32-bit Python 3.8b04 on Windows and then tried

pip install -I pywin32-225-cp38-cp38-win32.whl

and ended up needing to copy the DLLs from Python38-32\Lib\site-packages\pywin32_system32 to my embedding binary's root folder.

Where are these binaries

09/26/2019  09:56 PM           423,424 pythoncom38.dll
09/26/2019  09:56 PM           113,664 pywintypes38.dll

supposed to go when one runs

pip install -I pywin32-225-cp38-cp38-win32.whl

@azoellner
Copy link

For me the issue had been caused by old versions of pythoncom27.dll, pythoncomloader27.dll and pywintypes27.dll somewhere in the PATH before the ...\lib\site-packages\pywin32_system32. (See my comment above.) Thus Windows finds those old versions first, and they seem to have an incompatible public interface (exported symbols), hence the DLL load error.

Possibly the issue can be solved by prepending the pywin32_system32 instead of appending it, in the file pywin32.pth:

os.environ["PATH"]=('' if pywin32_system32 in os.environ["PATH"] else (pywin32_system32+";"))+os.environ["PATH"]

@landfillbaby
Copy link

pywin32_postinstall.py -install fixed it for me

@ebrahimraeyat
Copy link

Is it possible you have either a pythoncomXX.dll or pywintypesXX.dll in your system32 directory?

I copy this two dll into my system32 directory, but error still appear. also I add pywin32_system32 in my system environment varialble, but still did not work.

I installed python 3.7.4 in my wide system and import win32com works for me, but i want to able to run it from another location. thanks.

@xifarm
Copy link

xifarm commented Jul 3, 2020

my python is:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

i copy the pythoncom37.dll pywintypes37.dll to C:\Windows\System32

but not work for me.

there are error: ImportError: DLL load failed: %1 Win32 。

tonyroberts added a commit to pyxll/pyxll-jupyter that referenced this issue Feb 18, 2021
pywintypes38.dll isn't found when importing win32api after pip
installing pywin32, but explicitly importing pywintypes finds it and
allows win32api to be loaded.

See mhammond/pywin32#1399
@Avasam
Copy link
Collaborator

Avasam commented Mar 17, 2024

@azoellner 's suggestion of prepending the path has been done in 71afa71 for Python versions older than 3.8. For Python >= 3.8, the PATH environment variable isn't even used. This is included in pywin32==226.

Python 3.7 has also reached EOL (meaning no security fixes/support) and I'd recommend migrating over to 3.8+ (see #2207)

.exe installers are now deprecated #1939, so you should install from PyPI (ie: pip install pywin32>=226)

Given the sheer amount of "ImportError: DLL load failed: The specified module could not be found." issue duplication and old history, I'd like to consolidate the current state of these issues. So I'll close and reference back any issue that only has comments showing the issue:

  • from before November 10th, 2019 (pywin32<226)
  • using .exe installers
  • using Python < 3.8

Please also try https://github.com/mhammond/pywin32#troubleshooting before opening a new issue, or let us, and others, know here if it did fix your issue.

If you're having this issue with Jupyter Notebooks, refer to #1409 instead.
If you're having this issue using the Microsoft Store distribution of Python, refer to #1383 instead.
If you're having this issue with the Anaconda distribution of Python, refer to #1865 instead.

@Avasam Avasam changed the title import win32api fails after pip install pywin32 import win32api fails after pip install pywin32 (ImportError: DLL load failed: The specified module could not be found) Mar 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants