daniel-kukiela / nmt-chatbot

NMT Chatbot
GNU General Public License v3.0
387 stars 214 forks source link

The check_tensorflow_version function should be using integers, not strings #139

Open e-caste opened 5 years ago

e-caste commented 5 years ago

I've had an issue where my version of tensorflow (1.14.0) was considered an earlier version of the required 1.4.0. Since that is not true, I looked at the function that checks the version which is as following:

def check_tensorflow_version():
  min_tf_version = "1.4.0"
  if tf.__version__ < min_tf_version:
    raise EnvironmentError("Tensorflow version must >= %s" % min_tf_version)

And made the following correction:

def check_tensorflow_version():
  min_tf_version_str = "1.4.0"
  min_tf_version = [1, 4, 0]
  current_tf_version = [
    int(tf.__version__.split(".")[0]),
    int(tf.__version__.split(".")[1]),
    int(tf.__version__.split(".")[2])
  ]
  if current_tf_version[0] < min_tf_version[0]:
    raise EnvironmentError("Tensorflow version must >= %s" % min_tf_version_str)
  elif current_tf_version[0] == min_tf_version[0]:
    if current_tf_version[1] < min_tf_version[1]:
        raise EnvironmentError("Tensorflow version must >= %s" % min_tf_version_str)
    elif current_tf_version[1] == min_tf_version[1]:
        if current_tf_version[2] < min_tf_version[2]:
            raise EnvironmentError("Tensorflow version must >= %s" % min_tf_version_str)

This way the versions are checked by integers as opposed to strings, which in some cases like mine does not work.