64位python 2.5/2.6+windows 7“导入套接字”DLL加载错误

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

64-bit python 2.5/2.6+windows 7 "import socket" DLL load error

pythonwindowswindows-764-bit32bit-64bit

提问by Claudiu

I installed latest 64-bit Python 2.5. I run the shell, and try to import socket, and get:

我安装了最新的 64 位 Python 2.5。我运行 shell,并尝试import socket,然后得到:

>>> import socket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\socket.py", line 45, in <module>
    import _socket
ImportError: DLL load failed with error code 193

I try the same with 64-bit Python 2.6.6, and get:

我对 64 位 Python 2.6.6 进行了同样的尝试,并得到:

>>> import socket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python26-64\lib\socket.py", line 46, in <module>
    import _socket
ImportError: DLL load failed: %1 is not a valid Win32 application.

what's the deal? (I double-checked, yes, the OS is 64-bit).

这是怎么回事?(我仔细检查过,是的,操作系统是 64 位的)。

UPDATE: I also have 32-bit python installed on this machine.. if this is a conflict, how can I install both versions of python and have them behave nicely?

更新:我在这台机器上也安装了 32 位 python.. 如果这是一个冲突,我如何安装两个版本的 python 并让它们表现良好?

回答by David Heffernan

These two errors are the same error, code 193, reported two different ways. It is caused because your 64 bit Python is trying to load a 32 bit DLL.

这两个错误是同一个错误,代码193,两种不同的报出方式。这是因为您的 64 位 Python 正在尝试加载 32 位 DLL。

It's hard to say exactly why this has happened. Perhaps you installed some 32 bit Python modules by mistake. Perhaps there is some confusion in paths.

很难说到底为什么会发生这种情况。也许您错误地安装了一些 32 位 Python 模块。也许路径有些混乱。

However, often the easiest way to get around this sort of problem is to switch to 32 bit Python which runs impeccably on 64 bit Windows. A side benefit is that you will sometimes want to use modules that are only available in 32 bit form – 64 bit module support is still a little patchy.

但是,通常解决此类问题的最简单方法是切换到 32 位 Python,它可以在 64 位 Windows 上完美运行。一个附带的好处是您有时会想要使用仅以 32 位形式提供的模块 - 64 位模块支持仍然有点不完整。

回答by teeks99

I had this happen to me when I used py2exe to build a (32-bit) binary and then ran the 64 bit interpreter in the same directory. Apparently (and reasonably) it will pick the local instance of the socket module (which then loads a 32-bit dll) over the interpreter's socket module (which correctly loads a 64-bit dll).

当我使用 py2exe 构建(32 位)二进制文件,然后在同一目录中运行 64 位解释器时,我遇到了这种情况。显然(并且合理地)它会在解释器的套接字模块(正确加载 64 位 dll)上选择套接字模块的本地实例(然后加载 32 位 dll)。