Python 没有名为“win32api”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25314463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:02:36  来源:igfitidea点击:

No module named 'win32api'

pythonwinapipython-3.xmodulewin32com

提问by Alvaro Morales Solis

In Python 3.4 from Anaconda, I created a program and it is giving me and import error each time I run it. Using Spyder.

在 Anaconda 的 Python 3.4 中,我创建了一个程序,每次运行它都会给我和导入错误。使用 Spyder。

ImportError: No module named 'win32api'

导入错误:没有名为“win32api”的模块

I already have the pywin32 installed. And I can see the win32api.pyd under C:\Anaconda3\Lib\site-packages\win32

我已经安装了 pywin32。我可以在 C:\Anaconda3\Lib\site-packages\win32 下看到 win32api.pyd

This is the import code on my program:

这是我程序中的导入代码:

from tkinter import *
from tkinter import ttk
import tkinter.messagebox
import time
import requests #needs to be installed
import pymysql #needs to be installed
import csv 
import win32com.client #needs to be installed

import datetime

This is the whole error:

这是整个错误:

File "C:\Anaconda3\lib\site-packages\win32com\__init__.py", line 5, in <module>
import win32api, sys, os

ImportError: No module named 'win32api'

This is the only instance of Python I have installed. I uninstalled everything else and installed only Anaconda.

这是我安装的唯一 Python 实例。我卸载了其他所有东西,只安装了 Anaconda。

Searching online I got to something that said that it could be a problem with the PYTHONPATH. But honestly, I have no idea what they are talking about. So any noob help would be really appreciated. I am using Windows 7 by the way.

在网上搜索时,我发现这可能是 PYTHONPATH 的问题。但老实说,我不知道他们在说什么。所以任何菜鸟的帮助都将不胜感激。顺便说一下,我正在使用 Windows 7。

Thank you

谢谢

采纳答案by Oliver

The installation for pywin32 must have failed, or it is not for same OS bit architecture (say anaconda 64 bit and pywin32 32 bit). I recommend

pywin32 的安装肯定失败了,或者它不是用于相同的操作系统位架构(比如 anaconda 64 位和 pywin32 32 位)。我建议

  1. you uninstall pywin32,
  2. check what bit version of anaconda you are using, then
  3. install pywin32 for same version,
  4. verify that the installer indicates 100% success and there are no errors flagged in the installer's log window (it's rare but something may fail and the installer doesn't know).
  5. Then open a python console and type "import win32com".
  1. 你卸载pywin32,
  2. 检查您使用的是哪个版本的 anaconda,然后
  3. 为相同版本安装 pywin32,
  4. 验证安装程序是否显示 100% 成功,并且安装程序的日志窗口中没有标记错误(这种情况很少见,但可能会失败并且安装程序不知道)。
  5. 然后打开一个python控制台并输入“import win32com”。

If #5 fails to import win32com, then:

如果 #5 无法导入 win32com,则:

  1. try installing a different version of python, for example from python.org
  2. repeat steps 2 to 5 above but for new python instead of anaconda
  1. 尝试安装不同版本的 python,例如从 python.org
  2. 重复上面的步骤 2 到 5,但对于新的 python 而不是 anaconda

Could be that anaconda distributors did something to the python interpreter (although I didn't think so), or that some libs aren't registered right (see answer https://stackoverflow.com/a/17061853/869951for some more things to try).

可能是 anaconda 分销商对 python 解释器做了一些事情(虽然我不这么认为),或者某些库没有正确注册(请参阅答案https://stackoverflow.com/a/17061853/869951了解更多信息来试试)。

回答by neves

I had the same problem and solved it installing the module pywin32:

我遇到了同样的问题并通过安装模块 pywin32 解决了这个问题:

In a normal python:

在普通的蟒蛇中:

pip install pywin32

In anaconda:

在蟒蛇中:

conda install pywin32

My python installation (Intel? Distribution for Python) had some kind of dependency problem and was giving this error. After installing this module I never more saw it.

我的 Python 安装(英特尔?Python 发行版)存在某种依赖性问题,并出现此错误。安装此模块后,我再也没有看到它。

回答by threadpool

This should work:

这应该有效:

pip install pypiwin32

回答by LotiLotiLoti

As mentioned by outforawhile in comment, simply restarting the laptop fixed this for me.

正如outforawhile 在评论中提到的,只需重新启动笔记本电脑即可为我解决此问题。

It may be that this is required for Windows to register the DLL.

这可能是 Windows 注册 DLL 所必需的。