python:检查是否有重复的库文件

脚本check_lib_dup.py检查Windows系统中是否存在库文件重复,防止运行时冲突,搜索范围包括系统目录、Python路径和环境变量指定的路径。

检查是否有重复的库文件,可能造成运行时冲突。

编写 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

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值