Error on Pycharm



  • Silke Horn

    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 (e.g. "python install")?
    • Where do you get this error? Do you only get it in PyCharm or also using the interactive shell?
    Comment actions Permalink
  • Basem Alkhaleel
    • I used python 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.
    Comment actions Permalink
  • Jeff Burnett

    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/", 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/", 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.

    Comment actions Permalink
  • Eli Towle


    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


    Comment actions Permalink
  • Jeff Burnett

    That fixed it for me. Thanks for the quick response. 


    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk