Anna L
Anna L

Reputation: 51

AttributeError: module 'math' has no attribute 'dist'

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

Upvotes: 2

Views: 10167

Answers (1)

Anna L
Anna L

Reputation: 51

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

Upvotes: 3

Related Questions