Error on Pycharm
AnsweredI installed Gurobi on my Mac machine and used Conda to install Gurobi setup.py file. I am able to call Groubi and solve models sometimes; however, an error keeps showing sometimes after solving the model and other times before:
import gurobipy as gp
from gurobipy import GRB
from gurobipy import Model
m = Model('model')
### Output ###
Using license file /Users/BasemAlkhaleel/gurobi.lic
Academic license - for non-commercial use only
Traceback (most recent call last):
File "/Users/BasemAlkhaleel/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/193.6015.41/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_thrift.py", line 274, in frame_vars_to_struct
value = var_to_struct(v, str(k), evaluate_full_value=eval_full_val)
File "/Users/BasemAlkhaleel/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/193.6015.41/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_thrift.py", line 358, in var_to_struct
elif hasattr(v, '__len__') and not is_string(v):
File "model.pxi", line 344, in gurobipy.Model.__getattr__
KeyError: '__len__'
Unexpected error, recovered safely.
I hope someone could help me on this topic.
-
Could you give us some additional information:
- How exactly did you install the Gurobi Python package? Did you use conda ("conda install gurobi") or did you install it using setup.py (e.g. "python setup.py install")?
- Where do you get this error? Do you only get it in PyCharm or also using the interactive shell?
0 -
- I used python setup.py install
- I get the error using the python console inside Pycharm; however, if I run the file through a Jupyter notebook or through "Run" command in Pycharm I don't get the error. My python environment is managed through anaconda.
0 -
I had a similar error, but only when I was in debug mode in pycharm. In my case, gurobi is installed on linux. I have run many of the python examples successfully provided I don't try to set breakpoints.
Connected to pydev debugger (build 193.6494.30)
Using license file /home/jeff/local/gurobi/gurobi.lic
Traceback (most recent call last):
File "/mnt/b06cb29c-6a92-4382-ad49-9dd8e02b4c7e/home/jeff/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 282, in frame_vars_to_xml
xml += var_to_xml(v, str(k), evaluate_full_value=eval_full_val)
File "/mnt/b06cb29c-6a92-4382-ad49-9dd8e02b4c7e/home/jeff/.pycharm_helpers/pydev/_pydevd_bundle/pydevd_xml.py", line 369, in var_to_xml
elif hasattr(v, "__len__") and not is_string(v):
File "model.pxi", line 342, in gurobipy.Model.__getattr__
KeyError: '__len__'
Unexpected error, recovered safely.0 -
Hi,
This behavior will be fixed in the next bugfix release of Gurobi. Thanks for letting us know about it!
In the meantime, a possible workaround is to explicitly set the __len__ attribute of the Model object. E.g.:
model.__len__ = 1
Eli
0 -
That fixed it for me. Thanks for the quick response.
Jeff
0
Please sign in to leave a comment.
Comments
5 comments