Skip to content

Instantly share code, notes, and snippets.

@cwebber314
Last active April 23, 2026 20:33
Show Gist options
  • Select an option

  • Save cwebber314/a6bbc99f63273aa7cf4b54be9a1beb69 to your computer and use it in GitHub Desktop.

Select an option

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]  
Loading

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

Example fix: DLL load failed while importing win32api

Open PSSE and check which Python PSSE is using. In the PSSE, open the Python response terminal and run:

import sys
print(sys.path)

You should see something like:

"c:\\Python311", "c:\\Python311\\scripts" , ...

Now check the your system is using the same python. Open a new cmd.exe:

where python

This may return a different python version like:

c:\python39\python.exe

When this happens, update your "user environment variables" and remove the Python3.9 for your PATH and replace it with the proper Python3.11. Check your system PATH too - in some cases you need elevated permissions to edit your system PATH.
It's better to have python in your user PATH variable.

Now that you have Python3.11 setup, open a cmd and double check everything:

$ where python
c:\Python311\python.exe

$ where pip
c:\Python311\scripts\pip.exe

Install pywin32 which include the win32api library:

pip install pywin32

If your paranoid open a python.exe interpreter and:

import win32api

congrats - you fixed the win32api bug. Open up MOD again and see if it works.

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

In some cases your python install might be finding the wrong win32api library. This can happen when you have multiple python versions installed on your box and python looks at the wrong library (often because of the PATH env)

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'

Working environment example

Here's my environment where MOD works.

PATH env variable

No python directories in PATH env variable.

$ echo %PATH%

I don't like my python stuff in system env variables. You can put it in user env variables if you want to.

PYTHONHOME env variable

I have to set PYTHONHOME for PSSE to work:

$ echo %PYTHONHOME%
c:\python39

Make sure this points to the same location as your registry.

My python version:

$ python
Python 3.9.13 (main, Aug 25 2022, 23:51:50) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32

Registry

Registry points to python 3.9 64bit:

> reg query HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9\InstallPath

HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\3.9\InstallPath
    (Default)    REG_SZ    c:\Python39\

Launch Command

To test launch I use the command:

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

I like to remove the -embed option for testing. This makes it easier to see PSSE log.

MOD File Builder version

I'm using MOD File Builder 11.3.0.5

Feedback

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

@Jbonifield
Copy link
Copy Markdown

Common solution procedure:

cmd.exe:
where python

then user env variables:
set to PATH to find python3.11

Then cmd.exe
where python - should be 3.11
where pip -should be 3.11
pip install pywin32

check that win32api works
python.exe
import win32api

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