Ask Your Question

running PSSPY from Matlab

asked 2013-11-12 12:17:33 -0500

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 containing the following lines:

import os,sys

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


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 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 "" , 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!!!

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted

answered 2013-11-14 14:30:10 -0500

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
edit flag offensive delete link more

answered 2013-11-19 09:06:17 -0500

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

And in, 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();

edit flag offensive delete link more


@PieterJ Thanks

Bob gravatar imageBob ( 2013-11-19 20:37:29 -0500 )edit

answered 2013-11-18 04:21:33 -0500

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!!

edit flag offensive delete link more


@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 ( 2013-11-19 05:00:39 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools


Asked: 2013-11-12 12:17:33 -0500

Seen: 2,062 times

Last updated: Nov 19 '13