ImportError: No module named win32com.client

2019-01-07 19:30发布

问题:

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.

回答1:

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



回答2:

win32com.client is a part of pywin32

So, download pywin32 from here



回答3:

Try both pip install pywin32 and pip install pypiwin32.

It works.



回答4:

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.



回答5:

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")


回答6:

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 !



回答7:

Try this command: pip install pywin32

Note: Upgrade 'pip'(using, pip install --upgrade pip) if it gives the following error: " Could not find a version that satisfies the requirement pywin32>=223 (from pypiwin32) (from versions: ) No matching distribution found for pywin32>=223 (from pypiwin32) "