Ask Your Question
0

Python cannot import psspy

asked 2022-03-01 03:25:08 -0600

AML gravatar image

updated 2022-03-02 18:23:14 -0600

Hello everyone, My python version is 3.4.0, PSSE version is 34, I look all of the forum article but questions still here. This is my code:

import os

import sys

sys_path_PSSE=r'C:/Program Files (x86)/PTI/PSSE34/PSSPY27'  #or where else you find the psspy.pyc

sys.path.append(sys_path_PSSE)

os_path_PSSE=r' C:/Program Files (x86)/PTI/PSSE34/PSSBIN'  # or where else you find the psse.exe

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

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

import psspy

REEOR:ImportError: bad magic number in 'psspy': b'\x03\xf3\r\n'

Paths of PSSE and psspy are right, version of python and psspy correspond, I can't figure out why this happended.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2022-03-01 09:52:03 -0600

jconto gravatar image

Your code is calling for psspy27 (to use with python 2.7) If that is the intention, the code looks fine else change to psspy34

To run PSSe 34 with python 2.7

My guess is that in your PSSe set up, the default python is v.3.4, generating the error when loading psspy for python 2.7 Try the following:

- Find the link use to open a Command Prompt window (DOS window).  PSSe installation provides one on the desktop.
- Right click on that link, select properties and take note of the batch file name in the 'target' box.
- Edit the batch file ("C:\Program Files (x86)\PTI\PSSE34\SET_PSSE_PATH.BAT")
- Add a line to define the environ variable pythonhome as (do not leave spaces around the = char)
  Set PYTHONHOME=c:\python27\
- Save the batch file as 'run3427.bat' and on a copy of the DOS link, update the target property, clear the 'Start in' box and rename the DOS link to __PSSe3427

To use it, put a copy of the __PSSe3427 link in your working folder and double click it. Now run your python code.

A separate link can be done for other PSSe/python pair versions (run3434.bat, ... run3539.bat). To verify the value assigned to the environ var 'pythonhome', enter SET on a DOS window.

In my pc, this is the content of the run3427.bat:

@rem run3427.bat
@echo OFF
Set PSSEVERSION=34
Set PYTHONCODE=%userprofile%\Documents\Code\Python\
Set PYTHONHOME=c:\python27\
SET PSSEPATH=%PROGRAMFILES(x86)%\PTI\PSSE%psseversion%\
SET PSSPYPATH=%PSSEPATH%\PSSPY27
SET PATH=%PYTHONHOME%;%PYTHONHOME%SCRIPTs;%pssepath%PSSBIN;%PATH%
Set INCLUDE=%pssepath%PSSLIB;%INCLUDE%
echo ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo   %USERNAME%
echo   %PYTHONCODE%                                     
echo   PATHs set for PSS/E-34 + python 2.7
echo ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo %date% %time%
edit flag offensive delete link more

Comments

I want to use pythoon v3.4, change sys_path_PSSE to PSSPY34' ERROR:ImportError: DLL load failed: The specified module could not be found

AML gravatar imageAML ( 2022-03-01 15:39:57 -0600 )edit

I found this https://psspy.org/psse-help-forum/question/2751/importerror-dll-load-failed/ my psspyc.pyd in PSSPY34 folder and python is 32-bits

AML gravatar imageAML ( 2022-03-01 15:48:39 -0600 )edit

I solved the problem! Add PSSE34 path to environmental variable. Although VS code says "Import "psspy" could not be resolved" but the program can run now.

AML gravatar imageAML ( 2022-03-01 16:15:41 -0600 )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

1 follower

Stats

Asked: 2022-03-01 03:25:08 -0600

Seen: 1,384 times

Last updated: Mar 02 '22