IBMDecisionOptimization / Decision-Optimization-with-CPLEX-samples

20 stars 9 forks source link

Problem with Python #1

Closed MAbdelatti closed 5 years ago

MAbdelatti commented 5 years ago

Hi everybody, I have successfully installed cplex 12.8 and verified its working by running the gui studio... However, after installing the Python API using: python setup.py install --home python-home

and installed docplex using: pip install docplex

I found the following error when I run any example (e.g. python diet.py)

Attribute error: docplex has no attribute file

Any help? Thanks a lot.

vlkong commented 5 years ago

Hi Marwan,

Can you please provide the full output of your failing example run ? The traceback will help me make a diagnostic of what is going wrong. A dump of your sys.path will also help.

Thanks

MAbdelatti commented 5 years ago

Thank you vlkong for your response, below is the output message: python3 diet.py Traceback (most recent call last): File "diet.py", line 111, in <module> mdl = build_diet_model() File "diet.py", line 72, in build_diet_model mdl = Model(name='diet', **kwargs) File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/model.py", line 401, in __init__ self._environment = self._make_environment() File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/model.py", line 175, in _make_environment env = Environment.get_default_env() File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/environment.py", line 241, in get_default_env Environment._default_env = Environment.make_new_configured_env() File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/environment.py", line 236, in make_new_configured_env return Environment(start_auto_configure=True) File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/environment.py", line 49, in __init__ self.auto_configure() File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/environment.py", line 137, in auto_configure self._check_cplex() File "/home/marwan/.local/lib/python3.6/site-packages/docplex/mp/environment.py", line 145, in _check_cplex cplex_module_file = cplex.__file__ AttributeError: module 'cplex' has no attribute '__file__'

I will provide you the sys.path output as soon as I can.

By the way, I had a successful run on Python 2.7 this morning. The problem is in Python 3.6.

vlkong commented 5 years ago

Yes, the sys.path will help a lot python -c "import sys; print(sys.path)" should do it.

You mentionned that you "installed the Python API using python setup.py install --home python-home". I guess this is a reference to the CPLEX installation and python-home is some path on your machine. Just to make sure that everything is installed correctly (because you did not provide command logs, so I'm just guessing), did you make sure that python-home is different for your python 2.7 and your python 3.6 installations ?

The AttributeError: module 'cplex' has no attribute 'file' error often happens if you try to load a cplex module that does not match the right python version. So maybe here you installed the CPLEX wrappers for python 2.7 and try to use them on python 3.6 ?

MAbdelatti commented 5 years ago

Thank you very much vlokong, I really appreciate your help. I cleaned all cplex installations and re-installed them again. Currently, it works fine. I think I was having a conflict somewhere. Sorry for bothering you and thank you again.

vlkong commented 5 years ago

Your welcome, have fun.