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 pywin32==225 failed #1406

Closed
AndrewTsao opened this issue Sep 16, 2019 · 25 comments
Closed

import pywin32==225 failed #1406

AndrewTsao opened this issue Sep 16, 2019 · 25 comments

Comments

@AndrewTsao
Copy link

Hi, I install latest pywin32(pywin32 ==225) module, import failed. This is my python and os information.
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
This is error case.

Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: 找不到指定的程序。
@mhammond
Copy link
Owner

Does import pywintypes work? If not, is it possible there's a pywintypes36.dll in your c:\windows\system32 directory?

@fiber-space
Copy link

fiber-space commented Sep 16, 2019

I observe a similar problem with Python 27 ( here with a fresh pywin32==225 installation in a new virtualenv )

(py27) c:\Python\venv>python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywintypes
>>> import win32api
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.
>>>

@AndrewTsao
Copy link
Author

AndrewTsao commented Sep 17, 2019

Does import pywintypes work? If not, is it possible there's a pywintypes36.dll in your c:\windows\system32 directory?

I install pywin32 in venv, import pywintypes ok, it's from anaconda site-packages.

(.venv) C:\Users\caosw\sock-test>python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywintypes
>>> pywintypes.__file__
'D:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes36.dll'
>>> import pywin32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pywin32'
>>>
>>> sys.path
['', 'E:\\test\\credssp\\.venv\\Scripts\\python36.zip', 'D:\\ProgramData\\Anaconda3\\DLLs', 'D:\\ProgramData\\Anaconda3\\lib', 'D:\\ProgramData\\Anaconda3', 'E:\\test\\credssp\\.venv', 'E:\\test\\credssp\\.venv\\lib\\site-packages', 'E:\\test\\credssp\\.venv\\lib\\site-packages\\win32', 'E:\\test\\credssp\\.venv\\lib\\site-packages\\win32\\lib', 'E:\\test\\credssp\\.venv\\lib\\site-packages\\Pythonwin']

I find that pywin32.pth append to sys.path, after Anaconda3's path. so import pywintypes from anaconda's libs.

@mhammond
Copy link
Owner

>>> pywintypes.__file__
'D:\\ProgramData\\Anaconda3\\Library\\bin\\pywintypes36.dll'

Does Anaconda come with a pywin32 version? It looks like that pywintypes36.dll isn't the one from pywin32 225, which would explain the issue.

>>> import pywin32
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pywin32'
>>>

There's no 'pywin32' module in the package, so that's expected.

@mhammond
Copy link
Owner

mhammond commented Sep 22, 2019

I observe a similar problem with Python 27 ( here with a fresh pywin32==225 installation in a new virtualenv )

What is pywintypes.__path__ after you import it? I can't reproduce this problem locally, but can if an old copy of pywintypes is loaded.

@jamwil
Copy link

jamwil commented Sep 27, 2019

I am receiving the same error with 225 in a fresh Tox virtual environment. No issue in 224; not using Conda or anything exotic.

@stephanema
Copy link

I have the same Problem starting a script on windows python 3.7.4. 64 bit.
With 224 no problems, with 225 I get:

    import win32com.client
  File "D:\programme\python37\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden.

I switched back to 224 for now.

@mhammond
Copy link
Owner

mhammond commented Oct 5, 2019

See my above comment - I can only reproduce this if there's an old pywintypesXX.dll around. No one has yet answered my question above re pywintypes.__path__ - so there's literally nothing I can do at the moment to help with this issue.

@fiber-space
Copy link

(Running with pywin32==225):

Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:22:17) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywintypes
>>> pywintypes.__path__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__path__'

@zakhark
Copy link

zakhark commented Oct 5, 2019

On AWS Windows AMIs pywintypes.__file__ is C:\Program Files\Amazon\cfn-bootstrap\pywintypes27.dll

pywintypes.__path__ returns AttributeError: 'module' object has no attribute '__path__' as the comment above mentions.

@mhammond
Copy link
Owner

mhammond commented Oct 6, 2019

On AWS Windows AMIs pywintypes.__file__ is C:\Program Files\Amazon\cfn-bootstrap\pywintypes27.dll

Thanks for that info - that file will need to be replaced with the one that comes with pywin32-225. There's no way for the pywin32 installer to do that because it doesn't know that path exists.

@azoellner
Copy link

But possibly it could be solved by prepending instead of appending the pywin32_system32 in the file pywin32.pth, so that the pywin32's own DLLs will be found first. See my comment #1399 (comment).

@mhammond
Copy link
Owner

mhammond commented Oct 8, 2019

Possibly, although when I struck this issue locally, that didn't solve it for me. But yeah, I guess it can't hurt. There's also #1417

crwood added a commit to gridsync/gridsync that referenced this issue Oct 8, 2019
@Alezy80
Copy link

Alezy80 commented Oct 15, 2019

The same problem with pywin32==225 on clean Windows 10 x64 machine with Python 3.8. Fixed for me by symlinking (or just copy) two dll files from Python38\Lib\site-packages\pywin32_system32\ to Python38\ base path

@gabriellima
Copy link

gabriellima commented Oct 15, 2019

Same issue with v225 for me ("ImportError: DLL load failed: ...."), under a pipenv environment with python 3.7.1 x64.

Worked after force use of pywin32==224.

image

@fzumstein
Copy link

Running the postinstall.py script manually fixes this issue for 225. This steps wasn't required for 224. Run the script from the Scripts directory of your Python installation:

python C:\path\to\Scripts\pywin32_postinstall.py -install

@fiber-space
Copy link

python C:\path\to\Scripts\pywin32_postinstall.py -install

Yes, this works.

So I have to write a new deployment system / pip wrapper for my customer just to install a single dependent wheel which doesn't work out of the box after installation? Hmm....

@mhammond
Copy link
Owner

mhammond commented Nov 4, 2019

An error like "dll load failed, the specified procedure can not be found" typically means there's already a pywintypesXX.dll in the system32 directory, or somewhere else - typically put there by previously running the postinstall script. It's this other old one which has been loaded.

If there's only 1 pywintypesXX.dll on the entire system this error will not occur. So if you have only ever installed via pip, you should not have this issue - pip will never place the file in system32.

So if you are having this problem, you should try and find the duplicate and try to work out how it got there. As we see above, for jupyter appears to have shipped with the old version in some strange place, which causes this problem. The postinstall script probably helps fix this case too because the system32 directory ends up taking precedence. It's not clear to me whether all comments here refer to jupyter, but it is clear to me that everyone has the duplicate installed somewhere.

@mhammond
Copy link
Owner

mhammond commented Nov 4, 2019

(and for completeness, an error on 3.8 where the error is that the DLL can not be found (as opposed to a procedure can't be found) is different. I hope to make a new release in the next couple of days that will fix the 3.8 issue, and may help the "procedure not found" issue in some, but not all cases.)

@fzumstein
Copy link

Hey @mhammond thanks for pointing out the subtle difference and also the comment on xlwings/xlwings#1174. Things work indeed with a python.org installation on a fresh system. I got the "procedure" error on a conda env with Python3.7 where pywin32 was installed via pip. Removing the conda paths from the PATH env vars seems to have fixed this issue. Thanks!

@AT66
Copy link

AT66 commented Jan 10, 2020

Hey @mhammond thanks for pointing out the subtle difference and also the comment on xlwings/xlwings#1174. Things work indeed with a python.org installation on a fresh system. I got the "procedure" error on a conda env with Python3.7 where pywin32 was installed via pip. Removing the conda paths from the PATH env vars seems to have fixed this issue. Thanks!

I am having the issue on xlwings... which lead me to this conversation . "ImportError: DLL load failed: Die angegebene Prozedur wurde nicht gefunden." aka Procedure not found.
@fzumstein
Can you please elaborate on the procedure for "Removing the conda paths from the PATH env vars seems to have fixed this issue.".
sending the version of your pywin32 is ..

@fzumstein additionally can you tell me of the working/test/known combination of XLwings version ?? and pywin32 ?? version for Python 3.7.

Best regards

@AT66
Copy link

AT66 commented Jan 10, 2020

The same problem with pywin32==225 on clean Windows 10 x64 machine with Python 3.8. Fixed for me by symlinking (or just copy) two dll files from Python38\Lib\site-packages\pywin32_system32\ to Python38\ base path

@Alezy80
can you please tell which two files are you talking about when you said. "symlinking (or just copy) two dll files from"
Thanks

@Alezy80
Copy link

Alezy80 commented Jan 10, 2020

can you please tell which two files are you talking about

@AT66, I was copy pythoncom38.dll and pywintypes38.dll to base python folder

@fzumstein
Copy link

@AT66 you can follow these instructions https://www.computerhope.com/issues/ch000549.htm to edit your PATH. You might want to take out any path that leads to a python directory. If you use conda, it will set the PATH during a conda activate myenv. If you have further issues making xlwings work, I'd suggest to open an issue on xlwings directly, but the latest versions of pywin32 is always recommended.

@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.

Closing as duplicate of #1399

@Avasam Avasam closed this as completed 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