ImportError: No module named 'cplex' Python on Linux

蓝咒 提交于 2019-12-24 06:38:34

问题


I am trying to run python scripts on a HPC machine (RedHatEntrepriseServer). CPLEX module is already installed by adminastrators but I still have this error in importing cplex module in python.

ImportError: No module named 'cplex'

I know it is common error and I found that I may need to update PYTHONPATH variable with cplex home directory, but I can't find this home directory. Does anyone have an idea or suggestion to solve this problem?!

Many thanks!


回答1:


As mentioned in the comments, setting the PYTHONPATH environment variable is a perfectly reasonable solution here. Using PYTHONPATH has advantages, such as allowing you to easily switch between multiple versions of the CPLEX Python API. However, another option would be to ask your system administrator to install the cplex module. My guess is that they installed CPLEX Optimization Studio, but they did not actually install the CPLEX Python API into the system's default Python interpreter using the setup.py script (that is an optional step that would need to be performed separately). See the relevant documentation here. Yet another option would be for you to setup your own Python environment using virtualenv (see, for example, here).




回答2:


Thanks to skr and danche comments, here is how I solved the problem:

I looked for cplex location by using this command:

find / -iname "cplex"

Then I updated the PYTHONPATH variable with this location:

export PYTHONPATH=$PYTHONPATH:/local/software/cplex/12.6.1/cplex/python/2.6/x86-64_linux

I updated my .bashrc file with last command so each time I log in it is set automatically.



来源:https://stackoverflow.com/questions/45234827/importerror-no-module-named-cplex-python-on-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!