即使已安装,Pyomo 在 Linux 中也找不到 ipopt
我使用的是 Kali Linux,我需要安装 ipopt 才能与我目前正在学习的 Python 中的 pyomo 一起使用。我已经尝试了几件事,但没有一个能够在 pyomo 中运行 ipopt 。首先,按照他们的官方网站的说明不起作用(https://coin-or.github .io/Ipopt/INSTALL.html) 对于 pyomo,即使一切似乎都已安装:
sudo apt-get install gcc g++ gfortran git patch wget pkg-config liblapack-dev libmetis-dev
接下来,我尝试按照 coin-or repo 的建议使用 coinbrew
:
/path/to/coinbrew fetch Ipopt --no-prompt
/path/to/coinbrew build Ipopt --prefix=/dir/to/install --test --no-prompt --verbosity=3
/path/to/coinbrew install Ipopt --no-prompt
构建花了很长时间从来源,我不确定这是否有任何作用。
我的第三次尝试是使用 pip 安装 cyipopt (https://github.com/mechmotum/cyipopt)运行他们的存储库中的示例之一。使用 cyipot 可以很好地工作,但不能使用 pyomo,当我尝试运行它时,它仍然找不到解算器。在第四次尝试中,我直接从 https://ampl.com/ 下载了 ipopt linux64 dl/open/ipopt/。然后我解压该文件并将可执行文件 ipopt 复制到我的 /usr/bin 中,然后为其添加 +x 权限。我通过 ./ipopt 测试了可执行文件,它似乎在那里正常工作:
$ ipopt
No stub!
usage: ipopt [options] stub [-AMPL] [<assignment> ...]
Options:
-- {end of options}
-= {show name= possibilities}
-? {show usage}
-bf {read boundsfile f}
-e {suppress echoing of assignments}
-of {write .sol file to file f}
-s {write .sol file (without -AMPL)}
-v {just show version}
我继续在示例文件上运行它:
from pyomo.environ import *
V = 40 # liters
kA = 0.5 # 1/min
kB = 0.1 # l/min
CAf = 2.0 # moles/liter
# create a model instance
m = ConcreteModel()
# create the decision variable
m.q = Var(domain=NonNegativeReals)
# create the objective
m.CBmax = Objective(expr=m.q*V*kA*CAf/(m.q + V*kB)/(m.q + V*kA), sense=maximize)
# solve using the nonlinear solver ipopt
SolverFactory('ipopt').solve(m)
# print solution
print('Flowrate at maximum CB = ', m.q(), 'liters per minute.')
print('Maximum CB =', m.CBmax(), 'moles per liter.')
print('Productivity = ', m.q()*m.CBmax(), 'moles per minute.')
错误是:
WARNING: Could not locate the 'ipopt' executable, which is required for solver
ipopt
Traceback (most recent call last):
File "/media/sf_SharedFiles/Code/optimization/examplescalaroptimize.py", line 20, in <module>
SolverFactory('ipopt').solve(m)
File "/home/kali/.local/lib/python3.9/site-packages/pyomo/opt/base/solvers.py", line 512, in solve
self.available(exception_flag=True)
File "/home/kali/.local/lib/python3.9/site-packages/pyomo/opt/solver/shellcmd.py", line 128, in available
raise ApplicationError(msg % self.name)
pyomo.common.errors.ApplicationError: No executable found for solver 'ipopt'
我花了几个小时研究这个,但没有任何效果。
I'm using Kali Linux and I needed to install ipopt to use with pyomo in Python which I'm currently learning. I have tried several things and none of them have worked with trying to run ipopt in pyomo. First, following their official website's instructions did not work (https://coin-or.github.io/Ipopt/INSTALL.html) for pyomo even though everything seemed to install:
sudo apt-get install gcc g++ gfortran git patch wget pkg-config liblapack-dev libmetis-dev
Next, I attempted to use coinbrew
following coin-or repo's suggestion:
/path/to/coinbrew fetch Ipopt --no-prompt
/path/to/coinbrew build Ipopt --prefix=/dir/to/install --test --no-prompt --verbosity=3
/path/to/coinbrew install Ipopt --no-prompt
It took a long time to build from the source and I am not sure if this did anything.
My third attempt was installing cyipopt (https://github.com/mechmotum/cyipopt) with pip and running one of the examples there in their repo. That worked perfectly fine with using cyipot but not pyomo which still could not find the solver when I tried to run it. On my fourth attempt, I went ahead and downloaded the ipopt linux64 directly from https://ampl.com/dl/open/ipopt/. I then unzipped the file and copied the executable ipopt into my /usr/bin and then added +x permission to it. I tested out the executable by ./ipopt and it appears to work properly there:
$ ipopt
No stub!
usage: ipopt [options] stub [-AMPL] [<assignment> ...]
Options:
-- {end of options}
-= {show name= possibilities}
-? {show usage}
-bf {read boundsfile f}
-e {suppress echoing of assignments}
-of {write .sol file to file f}
-s {write .sol file (without -AMPL)}
-v {just show version}
I went ahead and ran it on an example file:
from pyomo.environ import *
V = 40 # liters
kA = 0.5 # 1/min
kB = 0.1 # l/min
CAf = 2.0 # moles/liter
# create a model instance
m = ConcreteModel()
# create the decision variable
m.q = Var(domain=NonNegativeReals)
# create the objective
m.CBmax = Objective(expr=m.q*V*kA*CAf/(m.q + V*kB)/(m.q + V*kA), sense=maximize)
# solve using the nonlinear solver ipopt
SolverFactory('ipopt').solve(m)
# print solution
print('Flowrate at maximum CB = ', m.q(), 'liters per minute.')
print('Maximum CB =', m.CBmax(), 'moles per liter.')
print('Productivity = ', m.q()*m.CBmax(), 'moles per minute.')
The error is:
WARNING: Could not locate the 'ipopt' executable, which is required for solver
ipopt
Traceback (most recent call last):
File "/media/sf_SharedFiles/Code/optimization/examplescalaroptimize.py", line 20, in <module>
SolverFactory('ipopt').solve(m)
File "/home/kali/.local/lib/python3.9/site-packages/pyomo/opt/base/solvers.py", line 512, in solve
self.available(exception_flag=True)
File "/home/kali/.local/lib/python3.9/site-packages/pyomo/opt/solver/shellcmd.py", line 128, in available
raise ApplicationError(msg % self.name)
pyomo.common.errors.ApplicationError: No executable found for solver 'ipopt'
I have spent several hours looking into this and nothing has worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嘿我也面临这个问题。我正在使用 Linux 系统的远程 HPC 中运行我的脚本。
但是,当我使用命令执行该文件时,它可以很好地工作并解决模型。当我使用pycharm运行脚本时,它不起作用,显示无法定位求解器。
那太奇怪了
Hey I also faced this problem. I was running my script in remote HPC with Linux system.
However, when I use command to execute the file, it works and solve the model very well. When I use pycharm run the script, it doesn't work, showing that the solver can not be located.
Thats super strange