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?
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 !
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.
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
win32com.client
is a part of pywin32
So, download pywin32 from here
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.
Try both pip install pywin32
and pip install pypiwin32
.
It works.
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
pip install pywin32
didn't work for me but pypiwin32
did.
Source: Stackoverflow.com