由于导入错误,Python-Modelica连接失败
我正在尝试使用Berkeley Simulations Lab提供的Python27块连接Modelica和Python: 我使用此块调用Python函数:由于导入错误,Python-Modelica连接失败,python,import,modelica,dymola,Python,Import,Modelica,Dymola,我正在尝试使用Berkeley Simulations Lab提供的Python27块连接Modelica和Python: 我使用此块调用Python函数: def Test2(WriteValues): ''' Connection Test - Works if started from Dymola ''' #Doing nothing and returning the input ReturnList=Write
def Test2(WriteValues):
''' Connection Test - Works if started from Dymola
'''
#Doing nothing and returning the input
ReturnList=WriteValues
return (ReturnList)
工作完美
现在我需要导入一些模块
#Importing Python modules works in general
import sys
import thread
import time
同样有效
只是现在我想导入一个模块,它不是Python的一部分,而是一个站点包:
def Test1(WriteValues):
'''Connection Test - Doesnt work if started from Dymola
'''
#Importing some Bacpypes Module
#Path is by default C:\Python27\Lib\site-packages\BACpypes-0.7-py2.7.egg\bacpypes
#My os is win7
from bacpypes.core import run
#Doing nothing and returning the input
ReturnList=WriteValues
return (ReturnList)
这是行不通的。无论我是在函数内部还是全局导入BACpypes模块,错误总是存在的
'module' object has no attribute 'argv'
同事们向我指出,这可能与多重进口问题有关。Modelica每10秒调用一次该函数(实时模拟)
如果我在Modelica之外调用函数Test1,就没有问题。使用Python27块只会失败
有人知道如何让BACpypes导入工作吗
更新日期2013-10-16:
我在Python目录中打印了脚本执行的sys.argv值和Modelica的执行
Python目录中的sys.argv:
['C:\\Python27\\Testcon.py']
sys.argv如果从Modelica内部调用函数:
['modpython']
这可能与我收到的错误消息有关吗?该错误是因为
bacpypes
使用sys.argv
,但Python解释器没有调用PySys\u SetArgv
这将在下一版本的Modelica Buildings库中修复,请参见