我正在尝试运行此程序:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from io import open
from multiprocessing import Pool
import buildingspy.simulate.Simulator as si
# Function to set common parameters and to run the simulation
def simulateCase(s):
''' Set common parameters and run a simulation.
:param s: A simulator object.
'''
s.setStopTime(86400)
# Kill the process if it does not finish in 1 minute
s.setTimeOut(60)
s.showProgressBar(False)
s.printModelAndTime()
s.simulate()
def main():
''' Main method that configures and runs all simulations
'''
import shutil
# Build list of cases to run
li = []
# First model
model = 'Buildings.Controls.Continuous.Examples.PIDHysteresis'
s = si.Simulator(model, 'dymola', 'case1')
s.addParameters({'con.eOn': 0.1})
li.append(s)
# second model
s = si.Simulator(model, 'dymola', 'case2')
s.addParameters({'con.eOn': 1})
li.append(s)
# Run all cases in parallel
po = Pool()
po.map(simulateCase, li)
# Clean up
shutil.rmtree('case1')
shutil.rmtree('case2')
# Main function
if __name__ == '__main__':
main()
我一直收到这个错误:
File "C:/Users/Toshiba/.spyder-py3/temp.py", line 11, in <module>
import buildingspy.simulate.Simulator as si
ModuleNotFoundError: No module named 'buildingspy'
我已经使用pip多次安装了包,没有任何改变。
我错过了什么?
This是此代码的来源。
答案 0 :(得分:0)
该错误可能是由于您的计算机上安装了多个python:
https://docs.python.org/3/installing/#work-with-multiple-versions-of-python-installed-in-parallel
请将以下行添加到您的脚本(或新脚本)并从Spyder运行一次,然后从控制台运行一次并比较输出:
import sys
print("python: {}".format(sys.version))
# also add the following if running from python 3
from shutil import which
print(which("python"))
必须使用pip安装Buildingspy,我建议使用以下命令安装它:
python -m pip install -U https://github.com/lbl-srg/BuildingsPy/archive/master.zip
Anaconda在“开始”菜单中添加Anaconda prompt,使用它来确保python.exe的路径正确。
一旦正确安装了BuildingsPy,您将遇到在Windows多处理无法从Spyder(或来自IPython / Jupyter)工作的问题,请同时阅读此问题:
https://github.com/lbl-srg/BuildingsPy/issues/179
您必须从命令行运行脚本。