Skip to main content

Error on Pycharm

Answered

Comments

6 comments

  • Official comment
    Simranjit Kaur
    Gurobi Staff Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Silke Horn
    Gurobi Staff Gurobi Staff

    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
  • Basem Alkhaleel
    Gurobi-versary
    First Comment
    First Question
    • 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
  • Jeff Burnett
    Gurobi-versary
    First Comment

    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
  • Eli Towle
    Gurobi Staff Gurobi Staff

    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
  • Jeff Burnett
    Gurobi-versary
    First Comment

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

    Jeff

    0

Post is closed for comments.