ImportError: DLL load failed while importing win32gui: 找不到指定的程序。解决方法
升级了win11之后,我发现pywin32无法使用了。明明已经安装了pywin32,但每次import win32gui都会提示这个报错:搜了一下也没有网友提供解决方法,于是上官网去找终于找到了,亲测有效:在 Python 中安装 pywin32 库安装完成后找到自己的 Python 根目录,在该目录下打开命令行。比如我使用的时 conda 的环境,目录是 ,我就在命令行中到这个目录,然后 。如果
·
升级了win11之后,我发现pywin32无法使用了。明明已经安装了pywin32,但每次import win32gui都会提示这个报错:
ImportError: DLL load failed while importing win32gui: 找不到指定的程序。
搜了一下也没有网友提供解决方法,于是上官网去找终于找到了,亲测有效:
-
在 Python 中安装 pywin32 库
pip install pywin32
-
安装完成后找到自己的 Python 根目录,在该目录下打开命令行。
比如我使用的时 conda 的环境,目录是
D:\ProgramData\Anaconda3\envs\torch
,我就在命令行中cd
到这个目录,然后conda activate torch
。如果是普通的 Python 就不用conda activate
这步了。在命令行中输入:
python.exe Scripts/pywin32_postinstall.py -install
执行后显示以下信息,问题即可解决。
Parsed arguments are: Namespace(install=True, remove=False, wait=None, silent=False, quiet=False, destination='D:\\ProgramData\\Anaconda3\\envs\\torch\\Lib\\site-packages')
Copied pythoncom39.dll to D:\ProgramData\Anaconda3\envs\torch\pythoncom39.dll
Copied pywintypes39.dll to D:\ProgramData\Anaconda3\envs\torch\pywintypes39.dll
You do not have the permissions to install COM objects.
The sample COM objects were not registered.
NOTE: PyWin32.chm can not be located, so has not been registered
Registered help file
Pythonwin has been registered in context menu
Creating directory D:\ProgramData\Anaconda3\envs\torch\Lib\site-packages\win32com\gen_py
Shortcut for Pythonwin created
The pywin32 extensions were successfully installed.
更多推荐
已为社区贡献1条内容
所有评论(0)