检查是否有重复的库文件,可能造成运行时冲突。
编写?check_lib_dup.py 如下
# -*- coding: utf-8 -*-
""" 搜索 Windows lib 目录中的某个.pyd """
import os
import sys
# Change this based on the library you wish to test
test_lib = "_socket.pyd"
def GetSystemDirectory():
from ctypes import windll, create_string_buffer, sizeof
GetSystemDirectory = windll.kernel32.GetSystemDirectoryA
buffer = create_string_buffer(260)
GetSystemDirectory(buffer, sizeof(buffer))
return os.fsdecode(buffer.value)
def library_search_paths():
return (
# Windows search paths
os.path.dirname(sys.argv[0]),
os.getcwd(),
GetSystemDirectory(),
os.environ["WINDIR"], # GetWindowsDirectory
*os.environ["PATH"].split(";"),
# regular Python search paths
*sys.path,
)
def check_library_duplicate(libname):
paths = [p for p in library_search_paths()
if os.path.exists(os.path.join(p, libname))]
print("Library %r found in %d locations:" % (libname, len(paths)))
for p in paths:
print("- %r" % p)
check_library_duplicate(test_lib)
运行 python?check_lib_dup.py