python - 如何修复“ImportError:没有名为 pssevrsn 的模块”
问题描述
尝试使用python调用psse。但是导入 dyntools 有问题。
from __future__ import division
import os, sys, math, csv, time
PSSPY_location = r'C:\Program Files (x86)\PTI\PSSE34\PSSPY27'
PSSE_location = r'C:\Program Files (x86)\PTI\PSSE34\PSSBIN'
sys.path.append(PSSPY_location)
os.environ['PATH'] += ';' + PSSPY_location
os.environ['PATH'] += ';' + PSSE_location
import socket
import struct
import numpy, copy
import initialize_mute as mt # mute all psse outputs
# import psse34
import dyntools
import psspy
import redirect
import dyntools
File ".\dyntools.py", line 51, in <module>
ImportError: No module named pssevrsn
进程以退出代码 1 结束
解决方案
PSSE 手册表明您需要在脚本中定义PSSPY_location
和PSSE_location
,但这里有另一个选项可以告诉 Python 您的 PSSE 安装在哪里。
在Python 安装目录中创建一个扩展名为.pth
,(例如__psspy__.pth
)的文件。site-packages
这可能C:\Python27\Lib\site-packages\__psspy.pth__
适合您。该文件的内容将只是C:\Program Files (x86)\PTI\PSSE34\PSSPY27
. 每当你启动你的 python 解释器时,它会.pth
在这个目录中查找文件中包含的路径,并在你进行import
语句时在这些位置查找 python 模块。
那么你的脚本应该如下:
import psse34
import psspy
import dyntools
import redirect
如果您仍然无法导入,请dyntools
确保它在应有的位置,即C:\Program Files (x86)\PTI\PSSE34\PSSPY27\dyntools.pyc
对于 PSSE v34,请记住始终import psse34
在导入任何其他与 PSSE 相关的 python 模块之前执行此操作。
推荐阅读
- keras - Keras 自定义 lambda 层:如何规范化/缩放输出
- objective-c - 在 Objective-C 中访问 Swift 方法
- jquery - Kendo MVC 日期过滤器定制
- node.js - 除了 bcrypt 之外的一种比较密码的方法
- java - 当我的应用不在焦点上时,如何运行滑动和点击命令?
- java - JFrame 包含带有 JButton 的 ToolBar,按下按钮将现有面板放在框架上
- .net - Team Explorer 2010 是免费的吗?
- intellij-idea - FXML 文件上 Intellij 配色方案的问题
- swift - 如何在 Swift 项目中管理文件夹?
- php - 在多表查询中缺少一些列名