Import Error: 没有名为 win32com.client 的模块

我目前正在使用 python 2.7并尝试打开一个 Excel 表。 使用以下代码时:

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')

我得到了这个错误:

Import Error: 没有名为 win32com.client 的模块

是否有任何可能得到的错误,因为我使用64位 Windows 机器?

389329 次浏览

win32com.client is a part of pywin32

So, download pywin32 from here

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

Try both pip install pywin32 and pip install pypiwin32.

It works.

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 !

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

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.

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.

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

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.

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

  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