无法在databricks上安装pyomo求解器ipopt

问题描述 投票:0回答:2

使用以下命令在 databricks 上成功安装 pyomo -

pip install 'pyomo[optional]'

输出- 成功安装 algopy-0.5.7 casadi-3.5.5 dill-0.3.5.1 et-xmlfile-1.1.0 mpmath-1.2.1 networkx-2.8.5 numdifftools-0.9.40 openpyxl-3.0.10 pint-0.19.2 ply -3.11 pyomo-6.4.1 python-louvain-0.16 pyyaml-6.0 sympy-1.10.1 xlrd-2.0.1 z3-solver-4.10.2.0

尝试在 databricks 上安装其求解器 ipopt 时出现以下错误 -

Collecting ipopt
  Downloading ipopt-1.0.3.tar.gz (42 kB)
     |████████████████████████████████| 42 kB 1.1 MB/s  eta 0:00:01
    ERROR: Command errored out with exit status 1:
     command: /databricks/python3/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/setup.py'"'"'; __file__='"'"'/tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-zpxip7hb
         cwd: /tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/
    Complete output (13 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/setup.py", line 194, in <module>
        ext_module_data = handle_ext_modules_general_os()
      File "/tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/setup.py", line 173, in handle_ext_modules_general_os
        **pkgconfig("ipopt"))
      File "/tmp/pip-install-_97_jyim/ipopt_5ccc28f94eb5408181b160df9c422798/setup.py", line 100, in pkgconfig
        output = sp.Popen(["pkg-config", "--libs", "--cflags"] + list(packages),
      File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: 'pkg-config'
Downloading ipopt-0.1.3.zip (109 kB)
     |████████████████████████████████| 109 kB 56.6 MB/s eta 0:00:01
Building wheels for collected packages: ipopt
  Building wheel for ipopt (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /databricks/python3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-_97_jyim/ipopt_8a62a84a8dcf4bc5a832cb6bb3713b52/setup.py'"'"'; __file__='"'"'/tmp/pip-install-_97_jyim/ipopt_8a62a84a8dcf4bc5a832cb6bb3713b52/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-8pgnfwqa
       cwd: /tmp/pip-install-_97_jyim/ipopt_8a62a84a8dcf4bc5a832cb6bb3713b52/
  Complete output (25 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.8
  creating build/lib.linux-x86_64-3.8/ipopt
  copying ipopt/__init__.py -> build/lib.linux-x86_64-3.8/ipopt
  running build_ext
  skipping 'src/cyipopt.c' Cython extension (up-to-date)
  building 'ipopt.cyipopt' extension
  creating build/temp.linux-x86_64-3.8
  creating build/temp.linux-x86_64-3.8/src
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/amitibo/code/Ipopt-3.10.1/include/coin -I/databricks/python3/lib/python3.8/site-packages/numpy/core/include -I/databricks/python3/include -I/usr/include/python3.8 -c src/cyipopt.c -o build/temp.linux-x86_64-3.8/src/cyipopt.o
  In file included from /databricks/python3/lib/python3.8/site-packages/numpy/core/include/numpy/ndarraytypes.h:1944,
                   from /databricks/python3/lib/python3.8/site-packages/numpy/core/include/numpy/ndarrayobject.h:12,
                   from /databricks/python3/lib/python3.8/site-packages/numpy/core/include/numpy/arrayobject.h:4,
                   from src/cyipopt.c:237:
  /databricks/python3/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
     17 | #warning "Using deprecated NumPy API, disable it with " \
        |  ^~~~~~~
  src/cyipopt.c:239:10: fatal error: IpStdCInterface.h: No such file or directory
    239 | #include "IpStdCInterface.h"
        |          ^~~~~~~~~~~~~~~~~~~
  compilation terminated.
  error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

注意 - 在 azure 上运行 databricks。

python-3.x azure ubuntu databricks pyomo
2个回答
2
投票

尝试了几种不同的安装方法后

ipopt
在Azure Databricks笔记本中对我有用的是

cd /tmp
wget https://ampl.com/dl/open/ipopt/ipopt-linux64.zip
unzip ipopt-linux64.zip
chmod +x ipopt
mv ipopt /usr/local/bin

然后在创建解算器时将其指向

ipopt

的路径
solver = pe.SolverFactory('ipopt', executable='/usr/local/bin/ipopt')

即使

ipopt
在我的路上,我也必须这样做。

我尝试按照此进行编译https://coin-or.github.io/Ipopt/INSTALL.html,但它永远不会将二进制文件放入

/usr/local/bin
中。另外通过
apt-get
pip
安装也不起作用


0
投票

这是我的两分钱...

经过多次尝试和错误,我发现,为了在优化过程中将“ipopt”求解器与 pyomo 结合使用,您首先需要完成以下步骤:

  1. 访问以下链接创建 AMPL 帐户并激活免费许可证:https://ampl.com/ce。确保您安全地复制您的许可证 UUID 以供以后使用。

  2. 转到终端并为您的项目激活适当的虚拟环境。

  3. 运行以下每个命令: python -m pip install amplpy --upgrade python -m amplpy.modules 安装硬币 python -m amplpy.modules activate XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX(将 X 替换为您的许可证 UUID)

  4. 此时,您的许可证应该已激活。在使用激活的许可证之前,您可能需要重新启动 AMPL。

  5. 最后,在终端中键入以下命令并复制“ipopt”求解器可执行文件的生成路径。调用求解器时,您需要在 Python 代码中添加此路径,即 opt = SolverFactory('ipopt',executable='/my/path/ipopt'): python -m amplpy.modules 查找 ipopt

这应该没有太大问题。希望这对我有帮助,直到我在 AMPL 网站上找到这个,才对我有用。另外,请记住模块“coin”内部有“ipopt”作为求解器之一(没有“ipopt”模块)。

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.