Python:附加系统路径以导入模块

2024-09-30 03:23:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从Python中名为“Power factory”的prgoram导入一个模块。Power factory文件所在的文件夹如下所示:

enter image description here

我编写了导入powerfactory模块的脚本,如下所示:

import sys
sys.path.append("PAth of folder")
import powerfactory as pf

当我运行上述代码时,它抛出以下错误:

ImportError: DLL load failed while importing powerfactory: The specified module could not be found.

我将power factory文件夹中的.dll文件复制到Python dll文件夹中,但运气不好。谁能帮我一下,我哪里出错了


Tags: 模块文件ofpathimport脚本文件夹factory
2条回答

我在网上搜索时发现了这个(从here

I am not able to import powerfactory module: DLL load failed Category: Scripting

If an error message appears when importing the powerfactory module stating “ DLL load failed: the specified module could not be found”, this means that Microsoft Visual C++ Redistributable for Visual Studio 2012 package is not installed on the computer.

To overcome this problem the user should add the PowerFactory installation directory to the os path variable within his python script.

import os

os.environ["PATH"] = r'C:\Program Files\DIgSILENT\PowerFactory 2016;' + os.environ["PATH"]

从digsilent文件夹复制.dll文件,例如Program Files\DIgSILENT\PowerFactory 2020 SP2A\Python\3.8\boost_python38-vc141-mt-x64-1_68.dll

并将.dll文件直接放入系统中

将其保存到C:\Windows\System32文件夹中。 &; 还将其保存到C:\Windows\SysWOW64文件夹中

你该走了

相关问题 更多 >

    热门问题