从带有matplotlib和cx_Freez的ctypes返回NotADirectoryError

2024-09-27 07:26:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用ctypes和matplotlib的脚本。在python控制台上一切正常,但是冻结时,即使导入matplotlib,我也会从ctypes得到NotADirectoryError。在

在调试.py公司名称:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import ctypes
import matplotlib    # produces NotADirectoryError in ctypes.WinDLL()

def main():
    dll = ctypes.WinDLL("CSSSM")

if __name__=="__main__":
    main()

在设置.py公司名称:

^{pr2}$

执行冻结脚本:

> build\exe.win32-3.3\debug.exe
Traceback (most recent call last):
  File "C:\Python\WinPython-32bit-3.3.2.3\python-3.3.2\lib\site-packages\cx_Free
ze\initscripts\Console3.py", line 27, in <module>
    exec(code, m.__dict__)
  File "debug.py", line 40, in <module>
  File "debug.py", line 36, in main
  File "C:\Python\WinPython-32bit-3.3.2.3\python-3.3.2\lib\ctypes\__init__.py",
line 353, in __init__
    self._handle = _dlopen(self._name, mode)
NotADirectoryError: [WinError 267] The directory name is invalid.

一。在

编辑:WinDbg,断点位于kernel32!LoadLibraryW,由eryksun评论。在

...
ModLoad: 65630000 65697000   O:\build\exe.win32-3.3\numpy.random.mtrand.pyd
ModLoad: 011e0000 01295000   O:\build\exe.win32-3.3\_hashlib.pyd
(304.898): Break instruction exception - code 80000003 (first chance)
eax=0023f400 ebx=65810815 ecx=00000000 edx=0023f39c esi=0023f2f8 edi=00f04b40
eip=750e3226 esp=0023f2f4 ebp=0023f2fc iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200202
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\syswow64\KERNELBASE.dll - 
KERNELBASE!DebugBreak+0x2:
750e3226 cc              int     3
0:000> bp kernel32!LoadLibraryW
*** WARNING: Unable to verify checksum for O:\build\exe.win32-3.3\_ctypes.pyd
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\syswow64\kernel32.dll - 
0:000> g
Breakpoint 0 hit
eax=02c6b940 ebx=1d1a8fc0 ecx=00000000 edx=0000004d esi=00f690a8 edi=00f6e1e8
eip=751548f3 esp=0023f2a4 ebp=0023f2b4 iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200202
kernel32!LoadLibraryW:
751548f3 8bff            mov     edi,edi
0:000> pt
eax=00000000 ebx=1d1a8fc0 ecx=7efdd000 edx=0000010b esi=00f690a8 edi=00f6e1e8
eip=75154905 esp=0023f2a4 ebp=0023f2b4 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200246
kernel32!LoadLibraryW+0x12:
75154905 c20400          ret     4
0:000> r @eax
eax=00000000
0:000> dt _TEB @$teb LastErrorValue
_ctypes!_TEB
   +0x034 LastErrorValue : 0x10b
0:000> g
eax=00000000 ebx=00000001 ecx=00000000 edx=00000000 esi=00000002 edi=003ef2d0
eip=77381f46 esp=0371fcc0 ebp=0371fe20 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00000246
ntdll!NtWaitForWorkViaWorkerFactory+0x12:
77381f46 83c404          add     esp,4

一。在

编辑2:WinDbg,断点位于ntdll!LdrLoadDll,由eryksun评论。在

...
ModLoad: 63570000 635d7000   O:\build\exe.win32-3.3\numpy.random.mtrand.pyd
ModLoad: 02170000 02225000   O:\build\exe.win32-3.3\_hashlib.pyd
(8e4.161c): Break instruction exception - code 80000003 (first chance)
eax=006af9b0 ebx=636e0815 ecx=00000000 edx=006af94c esi=006af8a8 edi=02754b40
eip=75f73226 esp=006af8a4 ebp=006af8ac iopl=0         nv up ei pl nz na po nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200202
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\syswow64\KERNELBASE.dll - 
KERNELBASE!DebugBreak+0x2:
75f73226 cc              int     3
0:000> bp ntdll!LdrLoadDll
*** WARNING: Unable to verify checksum for O:\build\exe.win32-3.3\_ctypes.pyd
0:000> g
Breakpoint 0 hit
eax=006af850 ebx=00000000 ecx=75fa182c edx=00000001 esi=00000000 edi=773f7da3
eip=773fc4dd esp=006af810 ebp=006af848 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200246
ntdll!LdrLoadDll:
773fc4dd 8bff            mov     edi,edi
0:000> pt
eax=c0000103 ebx=00000000 ecx=774243d3 edx=00000000 esi=00000000 edi=773f7da3
eip=773fc596 esp=006af810 ebp=006af848 iopl=0         nv up ei pl zr na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00200246
ntdll!LdrLoadDll+0xb9:
773fc596 c21000          ret     10h
0:000> r @eax
eax=c0000103
0:000> dt _TEB @$teb
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\Windows\syswow64\kernel32.dll - 
_ctypes!_TEB
   +0x000 NtTib            : _NT_TIB
   +0x01c EnvironmentPointer : (null) 
   +0x020 ClientId         : _CLIENT_ID
   +0x028 ActiveRpcHandle  : (null) 
   +0x02c ThreadLocalStoragePointer : 0x7efdd02c Void
   +0x030 ProcessEnvironmentBlock : 0x7efde000 _PEB
   +0x034 LastErrorValue   : 0
   +0x038 CountOfOwnedCriticalSections : 0
   +0x03c CsrClientThread  : (null) 
   +0x040 Win32ThreadInfo  : (null) 
   +0x044 User32Reserved   : [26] 0
   +0x0ac UserReserved     : [5] 0
   +0x0c0 WOW32Reserved    : 0x74882320 Void
   +0x0c4 CurrentLocale    : 0x407
   +0x0c8 FpSoftwareStatusRegister : 0
   +0x0cc SystemReserved1  : [54] (null) 
   +0x1a4 ExceptionCode    : 0n0
   +0x1a8 ActivationContextStack : _ACTIVATION_CONTEXT_STACK
   +0x1bc SpareBytes1      : [24]  ""
   +0x1d4 GdiTebBatch      : _GDI_TEB_BATCH
   +0x6b4 RealClientId     : _CLIENT_ID
   +0x6bc GdiCachedProcessHandle : (null) 
   +0x6c0 GdiClientPID     : 0
   +0x6c4 GdiClientTID     : 0
   +0x6c8 GdiThreadLocalInfo : (null) 
   +0x6cc Win32ClientInfo  : [62] 0
   +0x7c4 glDispatchTable  : [233] (null) 
   +0xb68 glReserved1      : [29] 0
   +0xbdc glReserved2      : (null) 
   +0xbe0 glSectionInfo    : (null) 
   +0xbe4 glSection        : (null) 
   +0xbe8 glTable          : (null) 
   +0xbec glCurrentRC      : (null) 
   +0xbf0 glContext        : (null) 
   +0xbf4 LastStatusValue  : 0xc0000103
   +0xbf8 StaticUnicodeString : _UNICODE_STRING ""
   +0xc00 StaticUnicodeBuffer : [261]  ""
   +0xe0c DeallocationStack : 0x005b0000 Void
   +0xe10 TlsSlots         : [64] (null) 
   +0xf10 TlsLinks         : _LIST_ENTRY [ 0x0 - 0x0 ]
   +0xf18 Vdm              : (null) 
   +0xf1c ReservedForNtRpc : 0x0095c7a8 Void
   +0xf20 DbgSsReserved    : [2] (null) 
   +0xf28 HardErrorMode    : 0
   +0xf2c Instrumentation  : [16] (null) 
   +0xf6c WinSockData      : (null) 
   +0xf70 GdiBatchCount    : 0x7efdb000
   +0xf74 InDbgPrint       : 0 ''
   +0xf75 FreeStackOnTermination : 0 ''
   +0xf76 HasFiberData     : 0 ''
   +0xf77 IdealProcessor   : 0 ''
   +0xf78 Spare3           : 0
   +0xf7c ReservedForPerf  : (null) 
   +0xf80 ReservedForOle   : (null) 
   +0xf84 WaitingOnLoaderLock : 0
   +0xf88 Wx86Thread       : _Wx86ThreadState
   +0xf94 TlsExpansionSlots : (null) 
   +0xf98 ImpersonationLocale : 0
   +0xf9c IsImpersonating  : 0
   +0xfa0 NlsCache         : (null) 
   +0xfa4 pShimData        : (null) 
   +0xfa8 HeapVirtualAffinity : 0
   +0xfac CurrentTransactionHandle : (null) 
   +0xfb0 ActiveFrame      : (null) 
   +0xfb4 FlsData          : 0x009558f8 Void

Tags: buildctypesesiexenulledxwin32eip
1条回答
网友
1楼 · 发布于 2024-09-27 07:26:49

导入的matplotlib(尤其是其numpy的导入)在冻结脚本中将OSError: The specified module could not be found从ctypes更改为NotADirectoryError: [WinError 267] The directory name is invalid。在

仅此而已。如果安装了DLL,一切正常。如果未导入matplotlib,则在冻结脚本中还会得到一个OSError: The specified module could not be found。但是如果matplotlib被导入并且脚本被冻结,那么OSError: The specified module could not be found就会变成奇怪的NotADirectoryError: [WinError 267] The directory name is invalid。在

相关问题 更多 >

    热门问题