Python for Power Systems

A blog for power systems engineers to learn Python.

Import PSSE Into Your Python Script

Here is a short video based on the tutorial in running PSSE from Python

Transcript

A look at importing Python into PSSE. Have you ever tried to import psspy into your Python script only to see ImportError: no module named psspy.

That means that Python was not able to find the psspy installation. Even though psspy comes with PSSE and we have Python installed on our computer. Python still can’t find it, and that is because Python is a completely separate program to PSSE.

Telling Python where PSSE is installed

We’re going to need to tell Python where PSSE is installed.

I’m going to import the operating system and system modules. I’m defining a variable PSSE_PATH which is where the PSSE that I have is installed. Yours might be different if you are using PSSE version 33, or if you are running 64 bit Windows.

Python has a sys.path which is a list of directories that it looks in. When you type in import it looks through every single one of these directories for the file that you have said to import. So later on where I’ve typed in import psspy Python will look through all of the directories and finally the one I’ve appended at the end PSSE_PATH will contain the psspy module.

Tell PSSE where PSSE is installed

We could run this program now and Python would find psspy. However we need to do one more thing. We need to tell PSSE where to find itself. PSSE is strange in that we need to set the environment variable PATH. We need to add to the end of that the PSSE installation path.

I’m not sure why PSSE needs to be told where it is, but your programs will crash at some point if you haven’t done that step.

Finally initialise PSSE

Let’s initialise with 100 buses. We can see that PSSE is in fact running.

That is how you can import PSSE into your python scripts. So that you can run the scripts from inside or outside of PSSE. You’ll notice that I didn’t open up the PSSE application at any point.

If you have any questions about how to solve a load flow with Python, get onto https://psspy.org/ and ask a question (it’s free).

Ideas for Python videos.