Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Last active August 10, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwebber314/a6bbc99f63273aa7cf4b54be9a1beb69 to your computer and use it in GitHub Desktop.
Save cwebber314/a6bbc99f63273aa7cf4b54be9a1beb69 to your computer and use it in GitHub Desktop.
Notes on getting PSSE and MOD to play nice with your python environment

PSSE MOD Debug Notes

MOD File Builder often has trouble connecting to the PSSE API if the environment on your machine isn't exactly like PSSE/MOD expects.

This document show some common issues with MOD File Builder install and how to fix them.

If you can't get PSSE to open without MOD, you need to debug that first. Here are some PSSE Debug Notes

The GUI and the Bridge

The MOD FIle Builder has two parts:

  • The GUI (Graphical User Interface)
  • The PSSE Bridge
graph LR
A[MOD GUI] --- B[PSSE Bridge]  

When you start MOD file buider it starts both of these parts seperately. The PSSE bridge often fails to startup correctly.

Under the hood, MOD starts the PSSE bridge with a command like this:

"C:\Program Files\PTI\PSSE35\35.4\PSSBIN\psse35.exe" -embed -pyfil "C:\Program Files (x86)\PTI\PSSMODFileBuilder\PSSPY\psspywndmsg.py"

If the startup fails, you see an error messge related to win32api in PSSE this in PSSE:

C:\Program Files (x86)\PTI\PSSMODFileBuilder appended to sys.path
Traceback (most recent call last):
File "C:\Program Files (x86)\PTI\PSSMODFileBuilder\PSSPY\psspywndmsg.py", line 25, in <module>
import win32api
ImportError: DLL load failed while importing win32api: %1 is not a valid Win32 application.

You may also see an error about DLL not found

Fix: DLL Not found

If you get an error about DLL's not found, you probably have a broken pywin32 installation. This library often has trouble with installs even without PSSE/MOD. See this StackOverflow question for all the problems people have with this package.

The following instructions need to be run in a cmd.exe terminal and assume you have the proper python in your PATH. You might need to run a command like this to setup your PATH first:

SET PATH=c:\Python39;c:\Python39\scripts;%PATH%

In many cases, you can just reinstall the pywin32 package to fix your problems:

pip install --upgrade pywin32

To sanity check the installation, try to import the module in your system python:

> python -c "import win32api;print(win32api.__file__)"
c:\Anaconda3\lib\site-packages\win32\win32api.pyd

Fix: Not a valid win32 application

To fix this issue we need to make sure the bridge is using the proper version of win32api. To fix this, we force the bridge to start with a known good environment.

Instructions:

  1. Start the PSSE bridge manually with the below script (may require tweaks)
  2. Start the MOD File Builder normally

Start the PSSE bridge manually like this:

SET PYTHONHOME=c:\Python39
"C:\Program Files (x86)\PTI\PSSE35\35.4\PSSBIN\psse35.exe" -pyver 39 -embed -gohome -pyfil "C:\Program Files (x86)\PTI\PSSMODFileBuilder\PSSPY\psspywndmsg.py"

ℹ️ psspywndmsg.py fiddles with the path and adds C:\Program Files (x86)\PTI\PSSMODFileBuilder to the PATH. This may be why the wrong version of win32api is found.

Fix: ModuleNotFoundError

To fix an error like this, install pywin32 using the pip instructions in this document:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'win32api'

Feedback

I've used this to fix a couple problematic MOD installs. If you see something new, leave some feedback in the comments below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment