2

I have code that works well in local Jupiter Notebook. I try to run the same code in google colab but there I get an AttributeError: module 'math' has no attribute 'dist'. The code below is couple of lines from my project

 import math
 distance = math.dist(x, y)

Update: the default version of python in google colab is 3.7.13

Anna L
  • 51
  • 1
  • 7

1 Answers1

3

Update: I found that the problem occurs because of version of python. The function dist was added to math module only since Python 3.8.

The colab successfully updated to 3.9.13

#install python 3.9
!sudo apt-get update -y
!sudo apt-get install python3.9

#change alternatives
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 
!sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 

#check python version
!python --version
#3.9.13

The code above I found on StackOverFlow here

Anna L
  • 51
  • 1
  • 7