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?
311 Answers
pip install pywin32 didn't work for me but pypiwin32 did.
win32com.client is a part of pywin32
So, download pywin32 from here
2Try 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 Try both pip install pywin32 and pip install pypiwin32.
It works.
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.
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.
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.
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 Try to install the "pywin32" file, you can find in
Install the version that you use in your IDLE, and try to install, after you can open your project and compile another turn!
thanks !
I'm using Visual Studio Code on a 64-bit laptop using Windows. I eventually got this to work! First install pywin32 as normal:
python -m pip install pywin32 If you're using Code Runner, you may need to make sure that you have the right path to your module in your code:
import sys sys.path.append("C:\\_path_to_virtual_environment\\Lib\\site-packages\\") import win32com.client as win32 Now change directory in your terminal windows to your scripts folder and run this:
python pywin32_postinstall.py -install This will change your error message to say you're missing the win32api module. To get this, install this:
python -m pip install pypiwin32 I wouldn't say I had a profound insight what all these commands do, but it (finally) solved my problem!
ImportError: No module named win32com.client
Open Command prompt in admin mode
Install win32com.client
a. By pip install method
pip install win32 If this throws error: version of win32 not determined then try installing via b. By pypi install methodb. By pypi install method
python -m pip install pywin32
3.Add program path to the python path