我安装了python 3.35,我收到了这个错误:
Traceback (most recent call last):
File "C:/Users/Augusto/PycharmProjects/Plot/Database.py", line 48, in <module>
import socket
File "C:\Python33\lib\socket.py", line 47, in <module>
import _socket
ImportError: DLL load failed: The specified module could not be found
我在Windows 7 64位上运行它。我尝试了两种Python安装(Windows x86-64 MSI安装程序和Windows x86 MSI安装程序),但两者都出现了相同的错误。我从路径中删除了python 2.7安装,导致错误,但没有运气。
编辑:os.system('listdlls %d' % os.getpid())
Base Size Path
0x000000001d000000 0xa000 C:\Python33\python.exe
0x0000000077b40000 0x1a9000 C:\Windows\SYSTEM32\ntdll.dll
0x00000000756f0000 0x3f000 C:\Windows\SYSTEM32\wow64.dll
0x0000000075690000 0x5c000 C:\Windows\SYSTEM32\wow64win.dll
0x0000000075680000 0x8000 C:\Windows\SYSTEM32\wow64cpu.dll
0x000000001d000000 0xa000 C:\Python33\python.exe
0x0000000077d20000 0x180000 C:\Windows\SysWOW64\ntdll.dll
0x0000000076b80000 0x110000 C:\Windows\syswow64\kernel32.dll
0x0000000076a20000 0x47000 C:\Windows\syswow64\KERNELBASE.dll
0x000000001e000000 0x294000 C:\Windows\SysWOW64\python33.dll
0x0000000075880000 0x100000 C:\Windows\syswow64\USER32.dll
0x0000000076500000 0x90000 C:\Windows\syswow64\GDI32.dll
0x0000000076b00000 0xa000 C:\Windows\syswow64\LPK.dll
0x0000000076760000 0x9d000 C:\Windows\syswow64\USP10.dll
0x0000000076800000 0xac000 C:\Windows\syswow64\msvcrt.dll
0x00000000768b0000 0xa0000 C:\Windows\syswow64\ADVAPI32.dll
0x0000000076590000 0x19000 C:\Windows\SysWOW64\sechost.dll
0x0000000076400000 0xf0000 C:\Windows\syswow64\RPCRT4.dll
0x0000000075750000 0x60000 C:\Windows\syswow64\SspiCli.dll
0x0000000075740000 0xc000 C:\Windows\syswow64\CRYPTBASE.dll
0x0000000076cd0000 0xc4a000 C:\Windows\syswow64\SHELL32.dll
0x0000000076700000 0x57000 C:\Windows\syswow64\SHLWAPI.dll
0x0000000062ba0000 0xbf000 C:\Windows\SysWOW64\MSVCR100.dll
0x0000000076050000 0x60000 C:\Windows\SysWOW64\IMM32.DLL
0x00000000757b0000 0xcc000 C:\Windows\syswow64\MSCTF.dll
0x00000000755d0000 0x35000 C:\Windows\SysWOW64\nvinit.dll
0x000000000f000000 0x6000 C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\detoured.dll
0x00000000739f0000 0x4c000 C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\nvd3d9wrap.dll
0x0000000075d80000 0x19d000 C:\Windows\syswow64\SETUPAPI.dll
0x0000000076c90000 0x27000 C:\Windows\syswow64\CFGMGR32.dll
0x0000000075990000 0x8f000 C:\Windows\syswow64\OLEAUT32.dll
0x00000000760b0000 0x15c000 C:\Windows\syswow64\ole32.dll
0x0000000075d60000 0x12000 C:\Windows\syswow64\DEVOBJ.dll
0x00000000739b0000 0x33000 C:\Program Files (x86)\NVIDIA Corporation\CoProcManager\nvdxgiwrap.dll
0x0000000074010000 0x16000 C:\Windows\SysWOW64\CRYPTSP.dll\rsaenh.dll
0x0000000066480000 0x15000 C:\Python33\DLLs\python3.dll
0x0000000065990000 0x41000 C:\Python33\lib\site-packages\PyQt4\QtSql.pyd
0x000000006a350000 0x34000 C:\Python33\lib\site-packages\PyQt4\QtSql4.dll
0x000000006a4f0000 0x273000 C:\Python33\lib\site-packages\PyQt4\QtCore4.dll
0x0000000076b10000 0x35000 C:\Windows\syswow64\WS2_32.dll
0x00000000763f0000 0x6000 C:\Windows\syswow64\NSI.dll
0x000000006f3d0000 0x69000 C:\Windows\SysWOW64\MSVCP100.dll
0x00000000685c0000 0x80d000 C:\Python33\lib\site-packages\PyQt4\QtGui4.dll
0x0000000076990000 0x7b000 C:\Windows\syswow64\COMDLG32.dll
0x0000000073270000 0x84000 C:\Windows\WinSxS_microsoft.windows.common-controls_6595b64144ccf1df_5.82.7601.18201_none_ec80f00e8593ece5\COMCTL32.dll
0x00000000718f0000 0x32000 C:\Windows\SysWOW64\WINMM.dll
0x0000000075610000 0x51000 C:\Windows\SysWOW64\WINSPOOL.DRV
0x0000000065970000 0x15000 C:\Python33\lib\site-packages\sip.pyd
0x0000000050d20000 0x19c000 C:\Python33\lib\site-packages\PyQt4\QtCore.pyd
0x0000000050770000 0x5ad000 C:\Python33\lib\site-packages\PyQt4\QtGui.pyd
0x0000000073bd0000 0x4c000 C:\Windows\SysWOW64pphelp.dll
答案 0 :(得分:4)
listdlls.exe的输出显示加载依赖关系ws2_32.dll(Winsock)没有问题,这至少可以说是令人惊讶的。所以问题是它试图加载错误的_socket.pyd。
在评论中确认,当绝对路径传递给imp.load_dynamic
时,加载_socket.pyd有效。事实证明,系统将环境变量PYTHONPATH
设置为包含C:\Python27\DLLs
。解决方案是简单地取消设置此环境变量。
我被错误消息抛弃了。通常这种情况会引发一个错误,即为不同的Python版本编译共享库。但是,Python 2.7的_socket.pyd与msvcr90.dll链接。此DLL不在DLL搜索路径上。它位于%windir%\WinSxS
的子目录中。通过查询C:\Python27\python.exe
的激活上下文找到它,它在嵌入式清单中指定了C运行时依赖项:
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="x86"
publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity>
</dependentAssembly>
</dependency>
因此,当在C:\Python33\python.exe
下运行时,尝试加载2.7 _socket.pyd会引发以下异常:
>>> imp.load_dynamic('_socket', r'C:\Python27\DLLs\_socket.pyd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: The specified module could not be found.
3.3和3.4是使用Visual Studio 2010而不是2008构建的,后者切换回在正常搜索路径上安装msvcr100.dll。所以为了比较,这是我尝试在3.4中导入3.3版_socket.pyd
时得到的错误:
>>> imp.load_dynamic('_socket', r'C:\Python33\DLLs\_socket.pyd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: Module use of python33.dll conflicts with this version of Python.