How to install the win32com python library

16

5

I am trying to install the win32com module. I know I should download the Python for Windows extension, but it does not work.

After I have installed Python for Windows and try import win32com.client, I get the following error message:

>>> import win32com.client

    Traceback (most recent call last):
      File "<pyshell#2>", line 1, in <module>
        import win32com.client
      File "C:\Python27\lib\site-packages\win32com\__init__.py", line 5, in <module>
        import win32api, sys, os

ImportError: No module named win32api

Trying to google for help on how to install win32api for Python does not help either; I am just referred to the Python for Windows extensions again.

NiklasR

Posted 2013-06-18T20:55:24.130

Reputation: 199

8Why on Earth was this migrated from Stack Overflow?! – Jean-François Corbett – 2017-11-13T13:35:19.020

1Did you install the right binary of Python for Windows extensions for your version of Python? For example, if you install 64-bit Python, then install the 32-bit extensions, the pure-Python modules (like win32con) will import, but the C-extension modules (like win32api) will not; if you install Python 2.6, then install the extensions for 2.7, they may import but crash later; etc. – None – 2013-06-18T21:00:59.550

Answers

8

  1. Start a command line with admin rights.
  2. python -m pip install pywin32
  3. C:\Program Files\Stackless36\Scripts>python pywin32_postinstall.py -install
  4. python C:\code\Python\speech\speak.py

Where speak.py consists of this text:

import win32com.client

speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak("It works, bitches.")

Working fine on Python 3.6.4 Stackless 3.1b3 060516 (v3.6.4-slp:9557b2e530, Dec 21 2017, 15:23:10) [MSC v.1900 64 bit (AMD64)] on win32. Vanilla CPython hangs out here:

C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'win32com'
>>> exit()

C:\Users\C\AppData\Local\Programs\Python\Python36-32>python.exe -m pip install pywin32
Collecting pywin32
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/d4/2d/b927e61c4a2b0aaaab72c8cb97cf748c319c399d804293164b0c43380d5f/pywin32-223-cp36-cp36m-win32.whl (8.3MB)
    100% |████████████████████████████████| 8.3MB 50kB/s
Installing collected packages: pywin32
Successfully installed pywin32-223
You are using pip version 9.0.3, however version 10.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

Cees Timmerman

Posted 2013-06-18T20:55:24.130

Reputation: 1 240

4

Check sys.path to make sure the directory where the module is installed is in there, otherwise you have to add it (google PYTHONPATH windows for some help with that.)

Rahul Ranjan

Posted 2013-06-18T20:55:24.130

Reputation:

I tried setting up PYTHONPATH in environment variable and still dont see this working. getting same error. – Soman Dubey – 2016-02-28T09:23:59.547

For those of you who now installed the package that OP linked, you'll need to restart your Python console (e.g. IDLE) for necessary changes to PYTHONPATH to populate such that your import will work. – SeldomNeedy – 2018-02-08T19:56:27.260

1Thanks for the advice. The problem turned out to be something different: for some reason there were two different Python installations in the registry, though both pointing to the same files. Re-installing it on both solved the problem. – None – 2013-06-19T06:15:07.220

2

I had the same problem only yesterday. I installed pypiwin32 using pip.

Try

>>pip install -U pypiwin32

at the command prompt

Make sure your Python package is in the system PATH.

Note that there are a few different ways to install Python modules, and as you have discovered not all of them work. pip install with -U worked for me with the pypiwin32 module (which contains win32com).

David Willis

Posted 2013-06-18T20:55:24.130

Reputation: 21

1

The -U switch stands for --upgrade and https://pypi.org/project/pypiwin32/ is a better-packed (.whl format) https://pypi.org/project/pywin32/ by the same devs. I read that python -m pip is preferred to just pip for path reasons.

– Cees Timmerman – 2018-07-21T22:49:28.387

This worked for me. Note that if you are receiving the error message, TypeError: 'module' object is not callable, try: python -m pip install -U pypiwin32 – datalifenyc – 2019-10-21T16:25:40.007

-2

look for the file in your computer by searching in all your computer "win32api" once you find it put it here C:\Python26\Lib\win32com "this suppossed you already install win32com library and you will find the file I think in" C:\Python26\Lib\site-packages\win32 "After all the file should be located in those two places in your computer for your module to work that's it in fini".

user347582

Posted 2013-06-18T20:55:24.130

Reputation: 11