Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.4 :ImportError: no module named win32api

I am using python 3.4 on windows 7. In order to open a doc file I am using this code:

import sys
import win32com.client as win32

word = win32.Dispatch("Word.Application")
word.Visible = 0
word.Documents.Open("MyDocument")
doc = word.ActiveDocument

I'M not sure why is this error popping up every time:

ImportError: no module named win32api

Although I have installed pywin32 from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32 and I have also checked the path from where I am importing. I have tried reinstalling pywin32 as well but that doesn't remove the error.

like image 814
Maxxie Avatar asked Aug 12 '14 06:08

Maxxie


2 Answers

Try to install pywin32 from here :

http://sourceforge.net/projects/pywin32/files/pywin32/

depends on you operation system and the python version that you are using. Normally 32bit version should works on both 32 and 64 bit OS.

EDIT: moved to https://github.com/mhammond/pywin32/releases

like image 197
Nima Soroush Avatar answered Sep 20 '22 21:09

Nima Soroush


This is a bug in the library itself, probably they used a different python implementation for creating this.

What they are trying to import is the site-packages\win32\win32api.pyd file, but the win32 folder is not in the path that python searches in, but site-packages is.

Try to replace the import win32api (inside win32com\__init__.py) to from win32 import win32api

like image 30
TulkinRB Avatar answered Sep 20 '22 21:09

TulkinRB