mac 上的 CPLEX Python API 问题

Problems with CPLEX Python API on a mac

我已经阅读了很多关于问题的帖子,但其中 none 可以解决我的问题。尽管我一直在关注 this blog,但当我尝试 运行 示例 src python 文件之一时,我仍然会遇到此错误:

Traceback (most recent call last):
  File "facility.py", line 25, in <module>
    import cplex
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/__init__.py", line 43, in <module>
    import callbacks
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/callbacks.py", line 48, in <module>
    from _internal._aux_functions import apply_freeform_two_args, apply_freeform_one_arg
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/__init__.py", line 22, in <module>
    import _list_array_utils
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_list_array_utils.py", line 13, in <module>
    import _pycplex as CPX
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex.py", line 19, in <module>
    _pycplex_platform = swig_import_helper()
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex.py", line 15, in swig_import_helper
   _mod = imp.load_module('_pycplex_platform', fp, pathname, description)
  File "/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/_pycplex_platform.py", line 23, in <module>
   from cplex._internal.py1013_cplex1251 import *
  ImportError: dlopen(/Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/py1013_cplex1251.so, 2): no suitable image found.  Did find:
    /Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/cplex/_internal/py1013_cplex1251.so: mach-o, but wrong architecture

不幸的是我不熟悉 /.bash_profile 但是我在最后添加的 link 中发布了什么。 有人可以帮我吗?

一个可能的解决方案是检查您是否可以手动将 cplex 目录复制到已安装的站点包中(您可能需要使用 sudo)。

从你的堆栈跟踪中我看到你已经安装了 cplex /Users/sb/Applications/IBM/ILOG/CPLEX_Studio1251/cplex/python/x86_darwin/

首先运行(我假设你python2.7)在互动shell:

import site; site.getsitepackages() 

有关此步骤的详细信息,请参阅 How do I find the location of my Python site-packages directory?

这将为您提供需要将 "cplex" 目录复制到的站点包目录。我假设它是 /Library/Python/2.7/site-packages from here

在 mac 然后 运行:

sudo cp -r ./cplex /Library/Python/2.7/site-packages/

这会将 cplex 手动设置为 python 安装的可导入包。因此,您应该能够在 python 交互式 shell 中导入 cplex。