我不确定什么时候在你的脚本中加载 DLL,但假设它被延迟到你可以做一些事情的地步,那么你可以自己加载库:
import os
import ctypes
try:
here = os.path.dirname(__file__)
except NameError:
here = os.getcwd()
dll = ctypes.CDLL(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll'))
del here
或使用pywin32
import os
import win32api
try:
dll = win32api.LoadLibrary('msvcr100.dll') #Never hurts to try
except win32api.error:
try:
here = os.path.dirname(__file__)
except NameError:
here = os.getcwd()
#Just to prove messing with PATH does something.
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(here, 'Microsoft.VC100.CRT')
dll = win32api.LoadLibrary('msvcr100.dll') #Give it another crank of the handle.
#Or alternatively without messing with PATH
dll = win32api.LoadLibrary(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll')) #Give it another alternative crank of the handle.
del here