Error when using winshell module: No module named 'win32'

234 views Asked by At
import winshell

r = list(winshell.recycle_bin())

for index, value in enumerate(r):
    print(index, value.original_filename())

This is the simple script I wrote, but when I try running it (or antyhing else that uses winshell) I get this error: ModuleNotFoundError: No module named 'win32'

And when I try running pip install win32 I get another error:

ERROR: Could not find a version that satisfies the requirement win32 (from versions: none) ERROR: No matching distribution found for win32

So now I'm even more confused. Why does winshell need a different module? That module doesn't even exist. Is it fine if I use some different module than the non-existent win32? If so which one? What am I supposed to do now?

1

There are 1 answers

0
Mody Developer On

First, you have to execute the script inside the Scripts directory, the pywin32_postinstall.py. Let’s say your Python directory is C:\python3, just follow the code below.

cd C:\python3
python Scripts/pywin32_postinstall.py -install

After that, the installation will drop the DLL files under the C:\Windows\System32. You need to move those two files ( pythoncom310.dll and pywintypes310.dll) to C:\python3\Lib\site-packages\win32 directory.

After that, you need to edit the python310._pth that you can find inside the Python installation folder. Then make the following changes:

Lib/site-packages
Lib/site-packages/win32
Lib/site-packages/win32/lib
Lib/site-packages/pythonwin
python310.zip

#Uncomment to run site.main() automatically
#import site

Save and try running your code again.

Troubleshoot

If you still get an error saying “ImportError: DLL load failed while importing win32api: The specified module could not be found.”, make sure you have copied the two dll files to Lib\site-packages\win32 directory. PythonWin32Api