Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 找不到带有gurobi:opt.solve的Pyomo,返回语法错误:非ASCII字符'\xc3&x27;在文件中<;stdin>;_Python_Gurobi_Pyomo - Fatal编程技术网

Python 找不到带有gurobi:opt.solve的Pyomo,返回语法错误:非ASCII字符'\xc3&x27;在文件中<;stdin>;

Python 找不到带有gurobi:opt.solve的Pyomo,返回语法错误:非ASCII字符'\xc3&x27;在文件中<;stdin>;,python,gurobi,pyomo,Python,Gurobi,Pyomo,经过数小时的错误追踪和尝试各种方法,我希望有人会有一个想法 我正在用Pyomo和gurobi作为解算器实现一个优化。以下代码: #编码=utf-8 from itertools import product import matplotlib.pyplot as plt from CentralOptimizationModel import create_central_optimizer from Schedules import gen_RES_curve,gen_load_curve,

经过数小时的错误追踪和尝试各种方法,我希望有人会有一个想法

我正在用Pyomo和gurobi作为解算器实现一个优化。以下代码: #编码=utf-8

from itertools import product

import matplotlib.pyplot as plt
from CentralOptimizationModel import create_central_optimizer
from Schedules import gen_RES_curve,gen_load_curve,gen_bes_schedules
from pyomo.environ import *
from pyomo.opt import *
import time


if __name__ == '__main__':


print("Create generation and load curves")
externalRES=gen_RES_curve()
clusterLoad=gen_load_curve()

print("Create BES schedules")
BES_schedule_dictionary=gen_bes_schedules()

print("Create the central optimizer for the given cluster information")
start_ModelCreator = time.time()
mod=create_central_optimizer(BES_schedule_dictionary,clusterLoad,externalRES)
end_ModelCreator = time.time()

print("Global Optimization")
opt=SolverFactory("gurobi")
start_Solver = time.time()
opt.options["resultfile=myModel.mps"]
print("Despues de opciones")
results = opt.solve(mod)
end_Solver = time.time()
我的一位同事说,这段代码正在他的电脑上运行,在我的电脑上崩溃了

文件“C:\Users\Blamblón\Anaconda3\lib\site packages\pyomo\opt\base\solvers.py”,第607行,在solve中 解算器(%s)未正常退出“%self.name” pyutilib.common.\u exceptions.ApplicationError:Solver(gurobi)未正常退出 错误:“[base]\site packages\pyomo\opt\base\solvers.py”,605,求解 解算器日志: 文件“”,第3行 SyntaxError:第3行文件中的非ASCII字符“\xc3”,但未声明编码

我尝试了各种方法,发现opt.solve根本不可访问,opt只提供了几个参数供选择,而solve不是其中之一

有人知道这是什么原因吗

非常感谢,
通过将接口更改为gurobi解决了问题。我将该行扩展到SolverFactory(“gurobi”,solver_io=“python”),代码现在正在运行。

看起来像是unicode问题。你能用另一个解算器重现这个问题吗?还有,你使用的是什么版本的Pyomo?我记得我修复了一个类似的问题,这个问题在不久前似乎只出现在Windows上,所以也许可以尝试更新您的Pyomo安装。我们通过向发送的gurobi.sh“script”文件添加一些额外的转义字符来修复这个问题。如果这不起作用,另一个解决方案是使用不同的接口来访问gurobi。如果您下载了gurobi\u ampl,则可以使用
SolverFactory(“gurobi”,solver\u io=“nl”)
。如果安装了Gurobi Python绑定(即,如果可以导入gurobipy),则可以使用
SolverFactory(“Gurobi”,solver\u io=“Python”)
。请在回答中添加您的,不要将其添加到问题中