简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM