coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
518 stars 92 forks source link

unable to import mip on a google cloud platform VM instance: module 'mip' has no attribute 'Var' #168

Closed imyiningliu closed 3 years ago

imyiningliu commented 3 years ago

Describe the bug unable to import mip on a google cloud platform VM instance because of the error module 'mip' has no attribute 'Var'

To Reproduce I've successfully run mip locally and on google colab. However, when I tried to import mip on a google cloud platform VM instance, I got the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yl4536/anaconda3/lib/python3.5/site-packages/mip/__init__.py", line 2, in <module>
    from mip.solver import Solver
  File "/home/yl4536/anaconda3/lib/python3.5/site-packages/mip/solver.py", line 9, in <module>
    class Solver:
  File "/home/yl4536/anaconda3/lib/python3.5/site-packages/mip/solver.py", line 292, in Solver
    e1: Union["mip.LinExpr", "mip.Var"],
  File "/home/yl4536/anaconda3/lib/python3.5/typing.py", line 537, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/home/yl4536/anaconda3/lib/python3.5/typing.py", line 494, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/home/yl4536/anaconda3/lib/python3.5/typing.py", line 494, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/home/yl4536/anaconda3/lib/python3.5/typing.py", line 185, in __subclasscheck__
    self._eval_type(globalns, localns)
  File "/home/yl4536/anaconda3/lib/python3.5/typing.py", line 172, in _eval_type
    eval(self.__forward_code__, globalns, localns),
  File "<string>", line 1, in <module>
AttributeError: module 'mip' has no attribute 'Var'

For reference, I set up the VM instance following this tutorial, and installed mip using pip install mip.

Desktop (please complete the following information):

jurasofish commented 3 years ago

I can reproduce on mac with python 3.5.1 and mip 1.12.0

Using python 3.5.6 works. Must have been an update to typing stuff. From memory typing was quite new in 3.5

imyiningliu commented 3 years ago

Upgrading python works; thank you!