ImportError: No module named win32com.client

2019-01-07 19:13发布

I am currently using python 2.7 and trying to open an excel sheet. When using the code below:

import os
from win32com.client import Dispatch

xlApp = win32com.client.Dispatch("Excel.Application")
xlApp.Visible = True
# Open the file we want in Excel
workbook = xlApp.Workbooks.Open('example.xls')

I get this error:

ImportError: No module named win32com.client

Is there any possibility of getting the error since I am using 64-bit Windows machine? Please help me with this.

7条回答
甜甜的少女心
2楼-- · 2019-01-07 19:31

I don't have any experience with this particular library (I'm just getting into it myself), but I did notice that you only imported the Dispatch class from the module. So you either need to just change your import as such:

import win32com.client

OR change your instance call like so:

xlApp = Dispatch("Excel.Application")
查看更多
欢心
3楼-- · 2019-01-07 19:32

win32com.client is a part of pywin32

So, download pywin32 from here

查看更多
Anthone
4楼-- · 2019-01-07 19:40

Try to install the "pywin32" file, you can find in https://github.com/mhammond/pywin32/releases

Install the version that you use in your IDLE, and try to install, after you can open your project and compile another turn!

thanks !

查看更多
成全新的幸福
5楼-- · 2019-01-07 19:44

pip install pywin32 didn't work for me but pypiwin32 did.

查看更多
【Aperson】
6楼-- · 2019-01-07 19:44

Try both pip install pywin32 and pip install pypiwin32.

It works.

查看更多
SAY GOODBYE
7楼-- · 2019-01-07 19:49

Is the module installed in the directory? Check python docs: https://docs.python.org/2/using/windows.html Also check out the links the other guys provided you.

查看更多
登录 后发表回答