Python 3.4 :ImportError: no module named win32api

核能气质少年 提交于 2019-11-27 08:05:50

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.

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

I encountered the same error yestoday with Python 3.6.1 on Windows 7, and resolved it by "pip install pypiwin32".

hanaQokus

Had the same error trying to import win32com.client (using Python 2.7, 64-bit). I agree with TulkinRB, there seem to be path issues, but the fix suggested did not work for me, since I also could not import win32.

Perhaps my fix will also work in Python 3.4.

Eventually, installing the .exe from SourceForge as an administrator (as suggested in Rina Rivera's answer here) allowed me to import win32com.client from IDLE, but not when I executed the script I was originally trying to run.

In the end, I discovered 3 differences in the sys.path that had been extended when I installed as admin and opened IDLE, but were not applied when executing a script. By extending the sys.path in my script, I was able to get rid of the import errors when I executed it:

import sys
sys.path.extend(('C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin'))

Finally, if you want more than a temporary fix, the sys.path could be permanently extended by establishing IDLESTARTUP or PYTHONSTARTUP variables (as described here and here).

I ended up debugging and copying and pasting the necessary files into the appropriate folders. It's a work-around until the bug is fixed, but it works.

You can create the init.py file inside the win32 folder and then go inside the win32com folder and change its __init.py file, where it is import win32api, change to from win32 import win32api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!