简体   繁体   English

没有名为“win32api”的模块

[英]No module named 'win32api'

In Python 3.4 from Anaconda, I created a program and it is giving me and import error each time I run it.在 Anaconda 的 Python 3.4 中,我创建了一个程序,每次运行它都会给我和导入错误。 Using Spyder.使用 Spyder。

ImportError: No module named 'win32api'导入错误:没有名为“win32api”的模块

I already have the pywin32 installed.我已经安装了 pywin32。 And I can see the win32api.pyd under C:\\Anaconda3\\Lib\\site-packages\\win32我可以在 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.这是我安装的唯一 Python 实例。 I uninstalled everything else and installed only Anaconda.我卸载了其他所有东西,只安装了 Anaconda。

Searching online I got to something that said that it could be a problem with the PYTHONPATH.在网上搜索时,我发现这可能是 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.顺便说一下,我正在使用 Windows 7。

Thank you谢谢

The installation for pywin32 must have failed, or it is not for same OS bit architecture (say anaconda 64 bit and pywin32 32 bit). pywin32 的安装肯定失败了,或者它不是用于相同的操作系统位架构(比如 anaconda 64 位和 pywin32 32 位)。 I recommend我建议

  1. you uninstall pywin32,你卸载pywin32,
  2. check what bit version of anaconda you are using, then检查您使用的是哪个版本的 anaconda,然后
  3. install pywin32 for same version,为相同版本安装 pywin32,
  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).验证安装程序是否指示 100% 成功,并且安装程序的日志窗口中没有标记错误(这种情况很少见,但可能会失败并且安装程序不知道)。
  5. Then open a python console and type "import win32com".然后打开一个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尝试安装不同版本的 python,例如从 python.org
  2. repeat steps 2 to 5 above but for new python instead of anaconda重复上面的步骤 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/869951 for some more things to try).可能是 anaconda 分销商对 python 解释器做了一些事情(虽然我不这么认为),或者某些库没有正确注册(请参阅答案https://stackoverflow.com/a/17061853/869951了解更多信息来试试)。

这应该有效:

pip install pypiwin32

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.我的 Python 安装(英特尔® Python 发行版)存在某种依赖性问题,并出现此错误。 After installing this module I never more saw it.安装此模块后,我再也没有看到它。

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 所必需的。

在安装 pywin32 之前试试这个

pip install pywinutils

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM