简体   繁体   English

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

[英]ImportError: no module named win32api

I am using Python 2.7 and I want to use pywin32-214 on Windows 7 .我正在使用Python 2.7 ,我想在Windows 7上使用pywin32-214 I installed pywin32-214 by using the msi installer.我使用msi安装程序安装了pywin32-214 But when I import win32api in my Python script, it throws the error:但是当我在我的 Python 脚本中导入win32api时,它会抛出错误:

no module named win32api. 

What should I do?我应该怎么办? Can I use pywin32 api for Windows 7 ?我可以将pywin32 api用于Windows 7吗?

这解决了我在哪里可以找到 Python 的 win32api 模块?

pip install pypiwin32

According to pywin32 github you must run根据pywin32 github你必须运行

    pip install pywin32

and after that, you must run之后,你必须运行

    python Scripts/pywin32_postinstall.py -install

I know I'm reviving an old thread, but I just had this problem and this was the only way to solve it.我知道我正在恢复一个旧线程,但我只是遇到了这个问题,这是解决它的唯一方法。

I had an identical problem, which I solved by restarting my Python editor and shell.我有一个相同的问题,我通过重新启动我的 Python 编辑器和 shell 解决了这个问题。 I had installed pywin32 but the new modules were not picked up until the restarts.我已经安装了pywin32 ,但新模块直到重新启动才被拾取。

If you've already done that, do a search in your Python installation for win32api and you should find win32api.pyd under ${PYTHON_HOME}\Lib\site-packages\win32 .如果您已经这样做了,请在 Python 安装中搜索win32api ,您应该会在${PYTHON_HOME}\Lib\site-packages\win32下找到win32api.pyd

I didn't find the package of the most voted answer in my Python 3 dist.我没有在我的 Python 3 dist 中找到投票最多的答案包。

I had the same problem and solved it installing the module pywin32:我有同样的问题并解决了安装模块pywin32:

In a normal python:在普通的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 it stopped appearing.安装此模块后,它停止出现。

After installing pywin32安装pywin32后

Steps to correctly install your module (pywin32)正确安装模块的步骤(pywin32)

  1. First search where is your python pip is present首先搜索你的 python pip 在哪里

    1a. 1a。 For Example in my case location of pip - C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts例如,在我的情况下,pip 的位置 - C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts

  2. Then open your command prompt and change directory to your pip folder location.然后打开您的命令提示符并将目录更改为您的 pip 文件夹位置。

     cd C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts C:\Users\username\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pypiwin32

Restart your IDE重启你的IDE

All done now you can use the module .现在一切都完成了,您可以使用该模块了。

The following should work:以下应该有效:

pip install pywin32

But it didn't for me.但它不适合我。 I fixed this by downloading and installing the exe from here:我通过从这里下载和安装 exe 解决了这个问题:

https://github.com/mhammond/pywin32/releases https://github.com/mhammond/pywin32/releases

This line: import win32com这一行: import win32com
got me the error no module named win32api .给我错误no module named win32api

Using this command in elevated terminal: pip install pywin32-ctypes and pip install pywin32 and based on the error displayed, replacing:在提升的终端中使用此命令: pip install pywin32-ctypespip install pywin32并根据显示的错误,替换:
import win32apifrom win32ctypes.pywin32 import win32api import win32apifrom win32ctypes.pywin32 import win32api
import pywintypesfrom win32.lib import pywintypes import pywintypesfrom win32.lib import pywintypes
import _win32sysloaderfrom win32 import _win32sysloader import _win32sysloaderfrom win32 import _win32sysloader
in your source file, or even the files of the packages that report the error (know what you are doing if you choose this approach) may solve this error.在您的源文件中,甚至是报告错误的包的文件(如果您选择这种方法,请知道您在做什么)可能会解决此错误。 But better would be to just add the corresponding directories into the python path variable, for better integration with the python loading system, more info here: https://realpython.com/python-import/但更好的办法是将相应的目录添加到 python 路径变量中,以便更好地与 python 加载系统集成,更多信息在这里: https ://realpython.com/python-import/

So I put this content:所以我把这个内容:

python38.zip
.
./lib
./lib/site-packages
./lib/site-packages/win32
./lib/site-packages/win32/lib
./lib/site-packages/win32ctypes/pywin32
./lib/site-packages/win32ctypes


# Uncomment to run site.main() automatically
#import site

(order DOES matter) into this file: <python_root_installation_directory>/python38._pth That way, correct libraries load when standard imports are used. (顺序很重要)到这个文件中: <python_root_installation_directory>/python38._pth这样,在使用标准导入时会加载正确的库。 If there is a cache import somewhere in the library, it will work, and the imports inside the libraries work as well.如果库中某处有缓存导入,它将起作用,并且库中的导入也起作用。

This works for me and my installation, so your environment may be set up differently and this guide may not be fully compatible, but it is a good step in solving the issue, maybe modification or extension of my steps above may lead to the solution in another distribution.这适用于我和我的安装,因此您的环境可能设置不同并且本指南可能不完全兼容,但这是解决问题的一个很好的步骤,也许修改或扩展我的上述步骤可能会导致解决方案另一种分布。

I had both pywin32 and pipywin32 installed like suggested in previous answer, but I still did not have a folder ${PYTHON_HOME}\Lib\site-packages\win32 .我按照上一个答案中的建议安装了pywin32pipywin32 ,但我仍然没有文件夹${PYTHON_HOME}\Lib\site-packages\win32 This always lead to errors when trying import win32api .尝试import win32api时,这总是会导致错误。

The simple solution was to uninstall both packages and reinstall pywin32 :简单的解决方案是卸载这两个软件包并重新安装pywin32

pip uninstall pipywin32
pip uninstall pywin32
pip install pywin32

Then restart Python (and Jupyter).然后重新启动 Python(和 Jupyter)。 Now, the win32 folder is there and the import works fine.现在, win32文件夹就在那里,导入工作正常。 Problem solved.问题解决了。

试试这个,它对我有用,它可以帮助你!

 pip install pywin32==225

let me summarize, correct me if wrong, as below:总结一下,如有错误请指正,如下:

# update to newest pywin32
python -m pip install -U pywin32 pypiwin32

# run the post-install @ref https://stackoverflow.com/questions/21343774/importerror-no-module-named-win32api
python %CONDA_PREFIX%\Scripts\pywin32_postinstall.py -install

# double check
python -c "print( __import__('win32api') )"

就我而言,唯一可行的方法是从以下网址下载适当的轮子: https ://pypi.org/project/pywin32/#files,然后使用--force-reinstall 进行安装。

pip install pywin32-300-cp37-cp37m-win_amd64.whl --force-reinstall

I found solution here: https://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/我在这里找到了解决方案: https ://www.ti-enxame.com/pt/python/pywin32-e-python-3.8.0/813327700/

I was able to run it on Spyder without error, but It wasn't working on cmd prompt我能够在 Spyder 上毫无错误地运行它,但它不能在 cmd 提示符下运行

I just import the module pywintypes before win32api我只是在 win32api 之前导入模块 pywintypes

import pywintypes
import win32api

for me was just working:对我来说只是工作:

import win32
from win32 import win32api

I tried to reinstall pywin32, installed different versions, but nothing could make pywin work.我试图重新安装 pywin32,安装了不同的版本,但没有什么能让 pywin 工作。 The only thing that did finally help me was running最终帮助我的唯一一件事就是跑步

python pywin32_postinstall.py

which is located at Anaconda3\Scripts folder.它位于 Anaconda3\Scripts 文件夹中。 Thanks for sameer_nubia for highlighting the location.感谢 sameer_nubia 突出显示该位置。

I've tried all of your answers and finally got a solution.我已经尝试了您所有的答案,终于找到了解决方案。 my issue was that I installed from both pip and python interpreter on my Pycharm IDE.我的问题是我从 pip 和 python 解释器安装在我的 Pycharm Z581D6381F3F35E4B364Z77 上。 I just removed win32compact from my interpreter and it works.我刚刚从我的解释器中删除了 win32compact,它可以工作。

I solve this by我解决这个问题

python -m pip install -U pywin32 pypiwin32

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

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