92
votes

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?

9
Just checking, did you install the extensions: sourceforge.net/projects/pywin32 It is not a standard library. - Dair
Your question has been answered here: superuser.com/questions/609447/… and here: stackoverflow.com/questions/7978510/… - Jordy19
Note that the above code gives an error even if the win32com is installed right. The 3rd line must be xlApp = Dispatch("Excel.Application") - ger.s.brett

9 Answers

156
votes

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

27
votes

win32com.client is a part of pywin32

So, download pywin32 from here

20
votes

Try this command:

pip install pywin32

Note

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)

upgrade 'pip', using:

pip install --upgrade pip
11
votes

Try both pip install pywin32 and pip install pypiwin32.

It works.

9
votes

I realize this post is old but I wanted to add that I had to take an extra step to get this to work.

Instead of just doing:

pip install pywin32

I had use use the -m flag to get this to work properly. Without it I was running into an issue where I was still getting the error ImportError: No module named win32com.

So to fix this you can give this a try:

python -m pip install pywin32

This worked for me and has worked on several version of python where just doing pip install pywin32 did not work.

Versions tested on:

3.6.2, 3.7.6, 3.8.0, 3.9.0a1.

4
votes

Had the exact same problem and none of the answers here helped me. Till I find this thread and post

Short: win32 modules are not guaranted to install correctly with pip. Install them directly from packages provided by developpers on github. It works like a charm.

2
votes

You must install the package pywin32:

pip install pywin32

After installation import win32com.client

Python has the “Python for Windows Extensions” package known as pywin32 that allows us to easily access Window’s Component Object Model (COM) and control Microsoft applications.

0
votes

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 !

0
votes

in some cases where pywin32 is not the direct reference and other libraries require pywin32-ctypes to be installed; causes the "ImportError: No module named win32com" when application bundled with pyinstaller.

running following command solves on python 3.7 - pyinstaller 3.6

pip install pywin32==227