Skip to main content
 首页 » 编程设计

python之创建文件时找不到 Pywin32

2025年05月04日9lidabo

当我通过 Python IDLE 3.4 32Bit 手动执行它时,导入和一切都按预期工作。但是当我尝试创建一个文件然后编写导入和所有其他代码时,出于某种奇怪的原因它找不到文件路径。是因为我将文件放在桌面上了吗?

import win32com.client as comclt 
 
wsh = comclt.Dispatch("WScript.Shell") 
wsh.AppActivate("Command Prompt") 
wsh.SendKeys("Hello") 

额外信息

Python 版本:3.4
Pywin32版本:pywin32-219.win32-py3.4

系统类型:32 位

错误信息:

Traceback (most recent call last): 
File "C:/Users/RepeaterCreeper/Desktop/tested.py", line 1, in <module> 
import win32com.client as comclt 
File "C:\Python34\lib\site-packages\win32com\__init__.py", line 5, in <module> 
import win32api, sys, os 
ImportError: DLL load failed: The specified module could not be found. 

如果您需要更多信息,请在下面的评论中告诉我,我一定会在看到您的评论后立即添加。

请您参考如下方法:

这很可能是 python 不在您的环境中的问题。

检查你的路径

Start -> Control Panel -> System -> Advanced. 
Click on Environment Variables, under System Variables, find PATH, and click on it. 
Add python directory to path ,end it with ;