user2293224
user2293224

Reputation: 2220

Python: Appending system path to import the module

I am trying to import a module from the prgoram called 'Power factory" in Python. The folder where power factory file located looks as follow:

enter image description here

I have written a script to import the powerfactory module as follow:

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

When I ran the above code, it throws the following error:

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

I copied the .dll file present in the power factory folder into the Python DLL folder but no luck. Could anyone help me where am I making the mistake?

Upvotes: 1

Views: 1911

Answers (2)

user15277257
user15277257

Reputation: 1

Copy the .dll file from your digsilent folder, eg. Program Files\DIgSILENT\PowerFactory 2020 SP2A\Python\3.8\boost_python38-vc141-mt-x64-1_68.dll

and place the .dll file directly in your system!

Save it to your C:\Windows\System32 folder. & Save it also to your C:\Windows\SysWOW64 folder.

You should be good to go.

Upvotes: 0

progmatico
progmatico

Reputation: 4964

Searching the net I found this (from 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"]

Upvotes: 1

Related Questions