Ask Your Question
0

How to reload psspy to different PSSE version in same script?

asked 2019-08-20 10:03:48 -0600

bronco7TX gravatar image

I have a python script where I'm performing acceptance testing of new v34 dynamics models. To do that I run a set of tests with the old model in v33 then run the same tests with the new model in v34. The problem I'm running into is trying to switch PSSE versions mid-script.

Initially I add the v33 BIN and LIB paths to sys.path and os.environ['PATH'] and PSSE intitializes in v33 properly. Next, before I run v34, I remove all v33 paths from sys.path and os.environ, then add in the v34 paths. When I go to initialize PSSE it still has v33 start not v34.

I think it has to do with how the previously imported psspy is still pointing to the v33 location, how do I force python to repoint psspy to the v34 location?

Sample Code:

ver = 33
# Remove old PSSE paths in sys.path and os.environ['PATH']
for p in list(sys.path):
    if 'PTI' in p:
        sys.path.remove(p)
        print 'Removed sys.path Path:' + p
os_paths = os.environ['PATH'].split(';')
for p in list(os_paths):
    if 'PTI' in p:
        os_paths.remove(p)
        print 'Removed os.environ Path:' + p
os.environ['PATH'] = ';'.join(os_paths)

if ver == 33:
    strPssePath = ''  # path to PSSE program executable
    if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE33'):  # 32-bit applications
        strPssePath = r'C:\Program Files (x86)\PTI\PSSE33'
    elif os.path.exists(r'C:\Program Files\PTI\PSSE33'):  # 64-bit applications
        strPssePath = r'C:\Program Files\PTI\PSSE33'

    sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
    sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')

elif ver == 34:
    strPssePath = ''  # path to PSSE program executable
    if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE34'):  # 32-bit applications
        strPssePath = r'C:\Program Files (x86)\PTI\PSSE34'
    elif os.path.exists(r'C:\Program Files\PTI\PSSE34'):  # 64-bit applications
        strPssePath = r'C:\Program Files\PTI\PSSE34'

    sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
    sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
    sys.path.append(os.path.join(strPssePath, 'PSSPY27'))
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')

import psspy
import redirect
redirect.psse2py()
psspy.psseinit(150000)

(Do some stuff in v33 then repeat code with '34' as the variable ver in the code above)

ver = 34
# Remove old PSSE paths in sys.path and os.environ['PATH']
for p in list(sys.path):
    if 'PTI' in p:
        sys.path.remove(p)
        print 'Removed sys.path Path:' + p
os_paths = os.environ['PATH'].split(';')
for p in list(os_paths):
    if 'PTI' in p:
        os_paths.remove(p)
        print 'Removed os.environ Path:' + p
os.environ['PATH'] = ';'.join(os_paths)

if ver == 33:
    strPssePath = ''  # path to PSSE program executable
    if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE33'):  # 32-bit applications
        strPssePath = r'C:\Program Files (x86)\PTI\PSSE33'
    elif os.path.exists(r'C ...
(more)
edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted
0

answered 2019-08-22 11:37:58 -0600

jconto gravatar image

BTW, PSSe is a 32-bit application so no need for 64-bit installations and V.33 can also use

import psse33

I run python scripts within a DOS window [double-click on a link such "PSS®E 33 Command Prompt", provided by PTI during PSSE installation] and I keep one link for v. 33 and another for v.34 in my working folder. Links can run a bat file as part of their starting process [right-click on the link and select properties, the Target box allows for such bat file entry. Check the link "PSS®E 33 Command Prompt"].

The link for v.33 will run a 'run33.bat' and the one for v.34 will run a 'run34.bat'. Inside each bat file, set right values for psseversion and other variables specific to each version, like pssebinpath or psspypath as needed. By running python scripts within DOS windows for its own version, now the python code just have to check if the environment variable 'psseversion' is 33 or 34 to import the corresponding pssexx module:

psseversion = int(os.environ['PSSEVERSION'])
exec('import psse%s'%psseversion)
import psspy
psspy.psseinit(150000)
edit flag offensive delete link more

Comments

I believe import psse33 is only supported from rev 33.X.

perolofl gravatar imageperolofl ( 2019-08-26 03:25:22 -0600 )edit
0

answered 2019-08-21 03:15:16 -0600

perolofl gravatar image

From rev 34 it is not needed to set the path. Just do import psse34, see below:

import sys,os
ver = 34

if ver == 33:
    strPssePath = ''  # path to PSSE program executable
    if os.path.exists(r'C:\Program Files (x86)\PTI\PSSE33'):  # 32-bit applications
        strPssePath = r'C:\Program Files (x86)\PTI\PSSE33'
    elif os.path.exists(r'C:\Program Files\PTI\PSSE33'):  # 64-bit applications
        strPssePath = r'C:\Program Files\PTI\PSSE33'

    sys.path.append(os.path.join(strPssePath, 'PSSBIN'))
    sys.path.append(os.path.join(strPssePath, 'PSSLIB'))
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSBIN')
    os.environ['PATH'] += ';' + os.path.join(strPssePath, 'PSSLIB')

elif ver == 34:
    import psse34

import psspy
import redirect
redirect.psse2py()
psspy.psseinit(150000)
print psspy.psseversion()
edit flag offensive delete link more

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

1 follower

Stats

Asked: 2019-08-20 10:03:48 -0600

Seen: 742 times

Last updated: Aug 22 '19