简体   繁体   English

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

[英]64-bit python 2.5/2.6+windows 7 “import socket” DLL load error

I installed latest 64-bit Python 2.5. 我安装了最新的64位Python 2.5。 I run the shell, and try to import socket , and get: 我运行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并让它们表现得很好?

These two errors are the same error, code 193, reported two different ways. 这两个错误是相同的错误,代码193,报告了两种不同的方式。 It is caused because your 64 bit Python is trying to load a 32 bit DLL. 这是因为您的64位Python正在尝试加载32位DLL。

It's hard to say exactly why this has happened. 很难确切说明为什么会发生这种情况。 Perhaps you installed some 32 bit Python modules by mistake. 也许您错误地安装了一些32位Python模块。 Perhaps there is some confusion in paths. 也许路径上有一些混乱。

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. 但是,解决此类问题的最简单方法是切换到32位Python,它在64位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位形式提供的模块 - 64位模块支持仍然有点不完整。

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

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

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