当前位置: 首页 > web >正文

Python笔记:在环境变量中增加了dll加载路径,python提示DLL加载失败

在环境变量中增加了dll加载路径,python提示DLL加载失败

1.问题描述

from PySide2 import QtCore
提示如下错误
ImportError: DLL load failed while importing QtCore: 找不到指定的模块。

2.问题原因

在Python3.8文档中的What’s New In Python 3.8找到如下说明:

•DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library. Note that Windows 7 users will need to ensure that Windows Update KB2533623 has been installed (this is also verified by the installer). (Contributed by Steve Dower in bpo-36085.)

在Python 3.8之前,Windows上的Python解释器会在环境变量PATH中搜索DLL文件。然而,从Python 3.8开始,这一行为发生了变化,Python解释器不再直接从PATH中导入DLL,而是采用了一种更严格的搜索策略,以提高安全性和可维护性。

3.8及以上的搜索路径为:

  • 系统目录
  • 当前dll或PYD文件所在目录
  • 通过os.add_dll_directory增加的目录

特别注意下,PATH与当前工作目录不再搜索。

3. 解决方案

  • 将dll放到系统目录下
  • 将dll放到当前dll或PYD文件所在目录
  • 通过os.add_dll_directory增加的dll的加载目录
http://www.xdnf.cn/news/6124.html

相关文章:

  • HTML:入门
  • Angular 知识框架
  • 【SQL】如何在 SQL 中统计结构化字符串的特征频率
  • 【位运算】常见算法公式使用
  • 360智语:以全栈技术重塑企业级智能体开发新标杆
  • 银行卡真伪验证助力金融合规-银行卡实名认证接口
  • 电机的导程和脉冲之间的关系
  • Ansible Roles 是一种用于层次化和结构化组织 Ansible Playbook 的机制。
  • SVG 知识详解:从入门到精通
  • 鸿蒙5.0项目开发——鸿蒙天气项目的实现(主页1)
  • 《Effective Python》第2章 字符串和切片操作——Python 字符串格式化的现代选择f-strings
  • Python 之 Flask 入门学习
  • 《P4391 [BalticOI 2009] Radio Transmission 无线传输 题解》
  • 完整的 CentOS 6.10 虚拟机安装启动脚本
  • spark中的转换算子
  • 易学探索助手-项目记录(九)
  • HTTP GET报文解读
  • 学习机器学习的体会与姓名性别预测案例分析
  • CMakeLists生成调用静态动态库可执行demo
  • 论语详解---缠中说禅(整理)
  • 通义千问-langchain使用构建(一)
  • ChromeDriver进程泄漏问题分析与最佳实践解决方案
  • 排序算法详解
  • Electron入门指南:用前端技术打造桌面应用
  • Socket API 核心函数详解
  • 一文了解 HTTP Content-Type:从基础到实战
  • 第六天——贪心算法——字符串分隔
  • 【C++】模板(初阶)
  • 从lightrag的prompt到基于openai Structured Outputs 的优化实现思路
  • 虚幻引擎5-Unreal Engine笔记之摄像机与场景捕获相关概念的解析