简体   繁体   中英

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

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

>>> 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:

>>> 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).

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?

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.

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.

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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