导入错误:DLL加载失败:%1不是有效的Win32应用程序,同时导入win32com
问题描述:
我想这个电子邮件发送sample code:导入错误:DLL加载失败:%1不是有效的Win32应用程序,同时导入win32com
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 21 15:36:00 2016
@author: Deepesh.Singh
"""
import win32com.client as win32
import psutil
import os
import subprocess
# Drafting and sending email notification to senders. You can add other senders' email in the list
def send_notification():
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]; [email protected]',
mail.Subject = 'Sent through Python'
mail.body = 'This email alert is auto generated. Please do not respond.'
mail.send
# Open Outlook.exe. Path may vary according to system config
# Please check the path to .exe file and update below
def open_outlook():
try:
subprocess.call(['C:\Program Files\Microsoft Office\Office15\Outlook.exe'])
os.system("C:\Program Files\Microsoft Office\Office15\Outlook.exe");
except:
print("Outlook didn't open successfully")
# Checking if outlook is already opened. If not, open Outlook.exe and send email
for item in psutil.pids():
p = psutil.Process(item)
if p.name() == "OUTLOOK.EXE":
flag = 1
break
else:
flag = 0
if (flag == 1):
send_notification()
else:
open_outlook()
send_notification()
,但不停的按下面的错误,当我在命令提示符下运行的代码:
C:\<>\Desktop\Exp>python sendemail.py
Traceback (most recent call last):
File "sendemail.py", line 40, in <module>
import win32com.client
File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os
ImportError: DLL load failed: %1 is not a valid Win32 application.
有人可以请指导我如何解决这个错误?或者他们是一个更好的方法来做到这一点?
谢谢。
答
您是否安装了用于Python的Win32 扩展?制作 确定你为你的系统选择了正确的 安装程序,而 版本的Python,否则 可能无法正常工作。
答
我重新安装了pywin32(32位版本),正如Trapli指出的那样,并且还安装了psutil模块并重新启动了我的系统。现在问题已解决,我可以发送电子邮件。 谢谢大家帮助我。
请告诉你的python版本和位?和操作系统? – Harsha
Python 2.7.13(v2.7.13:a06454b1afa1,Dec 17 2016,20:42:59)[MSC v.1500 32 bit(Intel)] on win32。 我正在使用Windows 10 64位操作系统 – Khan
我重新安装了pywin32(32位版本),正如下面的Trapli指出的那样,并且还安装了psutil模块并重新启动了我的系统。现在问题已解决,我可以发送电子邮件。谢谢大家帮助我。 – Khan