Solution to error when installing win32gui in Python: No module named 'win32gui'

Solution to error when installing win32gui in Python: No module named 'win32gui'

In Python, if win32gui is imported, but the corresponding component is not installed on the machine, an error will be reported when running the py program: ModuleNotFoundError: No module named 'win32gui'.

1

2

3

4

5

D:\Python\PY>MYPYAPP.py

Traceback (most recent call last):

  File "D:\Python\PY>MYPYAPP.py", line 12, in <module>

    import win32gui, win32ui, win32con, win32api

ModuleNotFoundError: No module named 'win32gui'

  

When the above problems occur, we cannot solve the problem by simply using pip install win32gui. The correct approach is:

1. Search for pywin32 in the https://www.lfd.uci.edu/~gohlke/pythonlibs/ page and find the whl corresponding to the number of bits of the local operating system and the installed python version.

For example: My operating system is win7 64-bit, and the python version is 3.8.x, then download pywin32‑304.0‑cp38‑cp38‑win_amd64.whl.

2. Install the file and it will prompt success.

1

2

3

4

D:\Python\PY>pip install pywin32-304.0-cp38-cp38-win_amd64.whl

Processing d:\python\py\pywin32-304.0-cp38-cp38-win_amd64.whl

Installing collected packages: pywin32

Successfully installed pywin32-304.0

 

1. From the " https://github.com/mhammond/pywin32/releases " website, download the "pywin32" installation program that is suitable for the "Python" version you installed. Such as "pywin32-225.win-amd64-py3.8.exe" and so on. This is very important. If the downloaded version does not match, all your efforts will be in vain.
2. Run the above download program as an administrator.
3. If the default installation directory is inappropriate (this will happen if several versions of "Python" are installed at the same time), when the "python" script calls the corresponding module in "win32", the error as pointed out in the article title will appear. Such an error message can be handled as follows:
4. Use a "python" script to describe the handling method as follows:
if several versions of "Python" are installed at the same time:
Please rename the "python" installation folder that is not currently in use.
Execute the "python pywin32_postinstall.py -install" command in the "\Scripts" folder of the current "python" installation directory.
Rename the above non-currently used "python" installation folder
else:
Execute the "python pywin32_postinstall.py -install" command in the "\Scripts" folder of the current "python" installation directory.

Congratulations, it was a success! ! !

Guess you like

Origin blog.csdn.net/qq_41879696/article/details/131910456