First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!

Ask Your Question
0

running PSSPY from Matlab

asked Nov 12 '13

PieterJ gravatar image

Dear all,

i'm trying to run PSSE with Python automation from Matlab, but can anyone of the community please tell me if i'm doing this correctly?

I have a python file test.py containing the following lines:

import os,sys

PSSE_LOCATION = r'C:\Program Files (x86)\PTI\PSSEUniversity33\PSSBIN'

sys.path.append(PSSE_LOCATION)

os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION

import psspy

and then follow the lines where i open a RAW file, and do power flow analysis**

then, in Matlab i use the command ! python test.py the exclamaton mark allows to run the command from the command line of the operating system.

However, this gives the error Traceback (most recent calls last): file "test.py" , line 8, in <module> import psspy 'Importerror', bad magic number in 'psspy': b'\x03\xf3\r\n'

Does anybody know how to correct this? Thanks!!!

3 answers

Sort by » oldest newest most voted
0

answered Nov 14 '13

terrytian gravatar image

The PSSE 33 python module psspy.pyc is in python version 2.7.

Your python interpreter that is initiated by matlab is not version 2.7. So you get a bad magic number error.

Only the python 2.7 interpreter can import version 2.7 python module 'XXX.pyc'

You can know your python interpreter version by the following python code:

import sys
print sys.version
link
0

answered Nov 19 '13

PieterJ gravatar image

I used the exclamation mark command in Matlab, to execute the command that follows the exclamation mark, in the operating system. Also, alternatively, you can use the system command:

[status,result] = system('command') calls upon the operating system to execute the given command. The resulting status and standard output are returned.

In my case, i invoked python from within matlab by typing the following in an m-file:

! C:\Python27\python.exe dynamic_simulation.py

And in dynamic_simulation.py, i placed the following code at the beginning of the file:

import os,sys

PSSELOCATION = r'C:\Program Files\PTI\PSSE33\PSSBIN' sys.path.append(PSSELOCATION) os.environ['PATH'] = os.environ['PATH'] + ';' + PSSE_LOCATION

import psspy

import redirect redirect.psse2py();

link

Comments

@PieterJ Thanks

Bob gravatar imageBob (Nov 20 '13)
0

answered Nov 18 '13

PieterJ gravatar image

thanks sir, that seems to be the problem indeed! i used the correct python version this time, and it works! Thanks again!!

link

Comments

@PieterJ The main program written by MATLAB calls python subroutines to achieve PSS/E simulation? So perfect, but how to written the MATLAB commands?

Bob gravatar imageBob (Nov 19 '13)

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.
Want to format code in your answer? Here is a one minute demo on Youtube

Add Answer

[hide preview]

Question Tools

Stats

Asked: Nov 12 '13

Seen: 3,080 times

Last updated: Nov 19 '13