DLL load failed: The specified procedure could not be found. win32api, sys, os
Asked Answered
M

3

2

I tried to convert .xls to .xlsx

this is my code:

import os
address = os.getcwd()
import win32com.client as win32

fname = address + "\\Bundles.xls"
fname2 = address + "\\searchresults.xls"
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel2 = win32.gencache.EnsureDispatch('Excel.Application')
wb = excel.Workbooks.Open(fname)
wb5 = excel.Workbooks.Open(fname2)

wb.SaveAs(fname+"x", FileFormat = 51)
wb5.SaveAs(fname2+"x", FileFormat = 51)    #FileFormat = 51 is for .xlsx extension
wb.Close()
wb5.Close()                               #FileFormat = 56 is for .xls extension
excel.Application.Quit()
excel2.Application.Quit()
print('File .xls convert .xlsx successful!!')

Then I got error:

Traceback (most recent call last):
  File "c:\Users\shenshuaic\Desktop\SFP Program\win32test.py", line 10, in <module>
    import win32com.client as win32
  File "C:\Users\shenshuaic\AppData\Local\Continuum\anaconda3\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: DLL load failed: The specified procedure could not be found.

I have already reinstall pywin32. It is still happen

Milly answered 11/12, 2019 at 0:56 Comment(0)
T
3

The traceback indicates that the problem actually occurs when importing win32api. I had the same issue while trying to import win32api directly (rather than importing win32.client). This answer helped: https://mcmap.net/q/240758/-how-to-fix-quot-importerror-dll-load-failed-quot-while-importing-win32api

(...) After copied the two files from Lib\site-packages\pywin32_system32 to C:\Windows\System32, it works. (...) The two files are pythoncom38.dll and pywintypes38.dll.

Typescript answered 11/8, 2020 at 15:32 Comment(2)
From an administrator prompt, go to the python Scripts directory, and run python -B pywin32_postinstall.pyPantechnicon
ALSO: if you have multiple venv's with different versions of pywin32, the Import Error will come right back when you switch the venv.Pantechnicon
S
1

This error comes from DLLs from pywin32 not being put in the right place during the installation process.

Running this in the anaconda prompt helped me:

conda install -c conda-forge pywin32
Sawmill answered 11/12, 2019 at 23:41 Comment(1)
it doesn't work bro Preparing transaction: done Verifying transaction: done Executing transaction: done PS C:\Users\shenshuaic> C:/Users/shenshuaic/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/shenshuaic/Desktop/SFP Program/SFP.py" Traceback (most recent call last): File "c:/Users/shenshuaic/Desktop/SFP Program/SFP.py", line 10, in <module> import win32com.client as win32 File "c:\Users\shenshuaic\Desktop\SFP Program\win32com_init_.py", line 5, in <module> import win32api, sys, os ImportError: DLL load failed: The specified procedure could not be found.Milly
R
0

I am using Spyder and I initially tried:

conda install pywin32 
import win32com.client

But kept getting an error. So I tried:

conda install -c conda-forge pywin32

and then

import win32com.client

It works perfectly.

Reign answered 29/11, 2021 at 9:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.