118

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?

4
  • 7
    Just checking, did you install the extensions: sourceforge.net/projects/pywin32 It is not a standard library. Commented May 26, 2014 at 6:47
  • 3
    Your question has been answered here: superuser.com/questions/609447/… and here: stackoverflow.com/questions/7978510/… Commented Jan 22, 2015 at 22:46
  • 3
    Note that the above code gives an error even if the win32com is installed right. The 3rd line must be xlApp = Dispatch("Excel.Application") Commented Jan 10, 2020 at 18:25
  • pip install pywin32 pypiwin32 winshell Commented Oct 13, 2022 at 14:10

13 Answers 13

192

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

Sign up to request clarification or add additional context in comments.

6 Comments

If you can't find pip on the command line, this works too: 'python -m pip install pypiwin32'
None of these worked for me. I tried both pypiwin32 and pywin32 and they both didn't work.
I get an 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) although I'm on Python 2.7.10 - does anyone know how to do it?
@MACC Having the same issue, but I'm running two versions of python and I think they're getting confused. Did you ever figure it out?
Note that pypiwin32 is an old and outdated repacking of pywin32.
|
31

win32com.client is a part of pywin32

So, download pywin32 from here

2 Comments

pywin32 is a dependency of pypiwin32
pip often does not run the post installation script, so manual install is the solution
26

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 

Comments

15

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.

Comments

12

Try both pip install pywin32 and pip install pypiwin32.

It works.

Comments

7

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.

Comments

7

Win32COM is (and was always) part of PyWin32.

1. PyWin32

[GitHub]: mhammond/pywin32 - Python for Windows (pywin32) Extensions is a Python wrapper over WinAPIs).
Documentation (WiP) can be found at [GitHub.MHammond]: Python for Win32 Extensions Help (or [ME.TimGolden]: Python for Win32 Extensions Help).

Lately, binaries (.whls) are published on [PyPI]: pywin32 (starting with v222 (from 20180121) - there are a couple of older records, but they don't contain any (useful) packages).

As many other software, it was previously hosted on [SourceForge]: mhammond - Python for Windows Extensions.
Binaries ((.exe) installers):

  • Were released there as well

    • Last one: v221 (from 20170329)
  • Are also available on GitHub (but they are deprecated)

2. PyPIWin32

Only exists on [PyPI]: pypiwin32.

Currently (at answer time), there are only 3 versions:

  1. v219 (from 20141203):

    • Contains .whls for various Python versions
  2. v220 (from 20170112):

    • Only contains .whls for Python 3.6
  3. v223 (from 20180226):

    • Only contains one .whl with no data (but having PyWin32 as a dependency)

Also check Mark Hammond's answer: [GitHub]: mhammond/pywin32 - Add CascadeWindows wrapper (@mhammond's comment) (emphasis is mine):

It existed before pywin32 itself supported being packaged as a wheel. I don't think it has much current value, but presumably there are still things out there that depend on it? TBH, I can't even recall who created it as I guess that's who we should ask (but know it wasn't me!)

From the above, one can only conclude that PyPIWin32 was just a playground for testing the newly introduced .whl packaging scheme, and now (maybe excepting the 1st version) is just garbage.

As a consequence:

Do NOT install PyPIWin32 (pip install pypiwin32)

Installing PyWin32 is all you need: python -m pip install pywin32 (one could also target a specific (PyWin32) version).

If it doesn't work after that, there are other issues.
Here are a couple of links with potential problems (and ways to overcome them), generic advice, and so on:

Comments

5

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.

Comments

3

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!

1 Comment

python -m pip install pywin32 worked for me on 64 bit Windows and Python 3.11.2
2

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 

Comments

0

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 !

Comments

0

ImportError: No module named win32com.client

  1. Open Command prompt in admin mode

  2. 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 method 

    b. By pypi install method

    python -m pip install pywin32

3.Add program path to the python path

Comments

-1

if you have to already installed library and still getting error. you need to check in which folder the library got installed and copy paste it to the correct folder.

Library should be installed in same directory to the python.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.