win32com 导入错误 python 3.4

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22490233/
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-19 01:02:29  来源:igfitidea点击:

win32com import error python 3.4

pythonpywin32

提问by foosion

I just installed python 3.4 64bit and tried to install win32com. I have downloaded pywin32-218.win-amd64-py3.4.exe and ran it without any problem. pip freeze reports pywin32==218. However, when I try to import win32com.client I get following error:

我刚刚安装了 python 3.4 64bit 并尝试安装 win32com。我已经下载了 pywin32-218.win-amd64-py3.4.exe 并运行它没有任何问题。pip freeze 报告 pywin32==218。但是,当我尝试导入 win32com.client 时,出现以下错误:

Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    import win32com.client
  File "C:\program files\Python34\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os
ImportError: DLL load failed: The specified module could not be found.

sys and os import without issue. import win32api is the problem.

sys 和 os 导入没有问题。导入 win32api 是问题所在。

Using the same procedure it worked fine for python 2.7.6 and python 3.3.4.

使用相同的程序,它适用于 python 2.7.6 和 python 3.3.4。

How can I fix this?

我怎样才能解决这个问题?

回答by TankorSmash

After I copied pywintypes26.dlland pythoncom26.dllto c:\Python26\Lib\site-packages\win32I solved the problem!

我复制后pywintypes26.dllpythoncom26.dllc:\Python26\Lib\site-packages\win32我解决了这个问题!

quoted from here

这里引用

回答by David Woakes

This worked without needing to copy DLLs in python 3.3.

这无需在 python 3.3 中复制 DLL 即可工作。

Why do these need to be copied as in 2.6? Surely this should be fixed by now!

为什么这些需要像 2.6 一样复制?当然,这应该现在就解决了!

After some additional research I found that all you need to do is run the post install script as administrator.

经过一些额外的研究,我发现您需要做的就是以管理员身份运行安装后脚本。

python C:\Python34\Scripts\pywin32_postinstall.py -install

It appears that the install script isn't doing this step correctly.

安装脚本似乎没有正确执行此步骤。

回答by Zero0evolution

I'm also running python 3.4 64 bit in Windows 7, and I had the same problem.

我也在 Windows 7 中运行 python 3.4 64 位,我遇到了同样的问题。

I solved it as suggested in this Stack Overflow answer. Basically, I added the path where pywintypes34.dllwas located to my system path and it worked.

我按照Stack Overflow answer 中的建议解决了它。基本上,我将所在的路径添加pywintypes34.dll到我的系统路径中并且它起作用了。

In my case it was C:\Python34\Lib\site-packages\pywin32_system32. There has to be 2 DLLs "pythoncom34.dll","pywintypes34.dll" in the path.

就我而言,它是 C:\Python34\Lib\site-packages\pywin32_system32。路径中必须有 2 个 DLL“pythoncom34.dll”、“pywintypes34.dll”。