R - Reticulate - Python - Pyomo - Solver (gurobi) did not exit normally
Hey community,
I tried to run the following code via R with reticulate and pyomo based on the solver "gurobi". The Python-code is working if I execute the code independently of R. Executing the code in R with the package "reticulate" doesn't work.
Information about the Python-code: A Simple Concrete Pyomo Model - https://pyomo.readthedocs.io/en/stable/pyomo_overview/simple_examples.html
Thanks in advance for your help!
Br, Alex
Code in Python:
from pyomo.environ import *
import pyutilib.subprocess.GlobalData
pyutilib.subprocess.GlobalData.DEFINE_SIGNAL_HANDLERS_DEFAULT = False
model = ConcreteModel()
model.x = Var([1,2], domain=NonNegativeReals)
model.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])
model.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)
opt = SolverFactory('gurobi')
opt.solve(model)
Code in R:
library("reticulate")
use_python("C:/Anaconda", required = TRUE)
setwd("C:/Users/SimpleConcretePyomoModel")
source_python("C:/Users/SimpleConcretePyomoModel/SimpleConcretePyomoModel.py")
Error in R:
Error in py_run_file_impl(file, local, convert) :
ApplicationError: Solver (gurobi) did not exit normally
ERROR: Solver (gurobi) returned non-zero return code (3221226505)
ERROR: Solver log: Fatal Python error: init_sys_streams: can't initialize sys
standard streams Traceback (most recent call last):
File "C:\Anaconda\lib\io.py", line 54, in <module>
ImportError: cannot import name 'open_code' from 'io' (unknown location)
Additional information:
python: C:/Anaconda/python.exe
libpython: C:/Anaconda/python38.dll
pythonhome: C:/Anaconda
version: 3.8.8 (default, Apr 13 2021, 15:08:03) [MSC v.1916 64 bit (AMD64)]
Architecture: 64bit
numpy: C:/Anaconda/Lib/site-packages/numpy
numpy_version: 1.20.3
pyomo_version: 5.7.2
reticulate_version: 1.20
gurobi_version: 9.1.2
RStudio_version: 1.4.1717
Spyder_version: 5.0.5
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
Post is closed for comments.
Comments
1 comment