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

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.dtcms.com/a/191008.html

相关文章:

  • 匿名函数lambda、STL与正则表达式
  • 最小二乘拟合曲线
  • bat——自动重启程序
  • 酒店行业冰与火:一边流拍,一边扩张
  • 第22篇:Linux系统的Switch字符设备驱动设计
  • 数据的模型分析及可视化
  • 【python机器学习】Day 25 异常处理
  • 日本动漫风格人像街拍Lr调色预设,手机滤镜PS+Lightroom预设下载!
  • 《Python星球日记》 第71天:命名实体识别(NER)与关系抽取
  • Java—封装、继承与多态
  • 通过Ollama读取模型
  • CSS 锚点滑动效果的技术
  • 【C/C++】高阶用法_笔记
  • Tensorflow2保存和加载模型
  • 【Redis】缓存穿透、缓存雪崩、缓存击穿
  • Java 异常处理之 BufferUnderflowException(BufferUnderflowException 概述、常见发生场景、避免策略)
  • C 语言学习笔记(8)
  • 因果推断 | 用SHAP分值等价因果效应值进行反事实推理
  • 【Linux】掌握 setsid:让进程脱离终端独立运行
  • 东芝新四款产品“TB67Z830SFTG、TB67Z830HFTG、TB67Z850SFTG、TB67Z850HFTG系列三相栅极驱动器ic三相栅极驱动器IC
  • 软件测试--入门
  • 【Linux】Ext系列文件系统
  • 鸿蒙-5.1.0-release构建编译环境
  • Oracle中的select1条、几条、指定范围的语句
  • 每日算法-250514
  • 【golang】网络数据包捕获库 gopacket
  • 嵌入式系统中WAV音频文件格式详解与处理实践
  • 【CustomPagination:基于Vue 3与Element Plus的高效二次封装分页器】
  • Lightpanda开源浏览器:专为 AI 和自动化而设计的无界面浏览器
  • 安卓基础(Bitmap)