简体   繁体   English

AttributeError:模块“数学”没有属性“dist”

[英]AttributeError: module 'math' has no attribute 'dist'

I have code that works well in local Jupiter Notebook.我的代码在本地 Jupiter Notebook 中运行良好。 I try to run the same code in google colab but there I get an AttributeError: module 'math' has no attribute 'dist'.我尝试在 google colab 中运行相同的代码,但出现 AttributeError:模块“math”没有属性“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更新:google colab中python的默认版本是3.7.13

Update: I found that the problem occurs because of version of python.更新:我发现问题是由于 python 的版本引起的。 The function dist was added to math module only since Python 3.8.仅在 Python 3.8 之后,才将 function dist 添加到数学模块。

The colab successfully updated to 3.9.13 colab成功更新到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我在 StackOverFlow 上找到的上面的代码here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python AttributeError:'module'对象没有属性'DIST_L2' - Python AttributeError: 'module' object has no attribute 'DIST_L2' AttributeError:模块“sklearn.metrics._dist_metrics”没有属性“DatasetsPair” - AttributeError: module 'sklearn.metrics._dist_metrics' has no attribute 'DatasetsPair' Ansible 错误:AttributeError:模块“平台”没有属性“dist” - Ansible error: AttributeError: module 'platform' has no attribute 'dist' AttributeError: 'list' object 没有属性 'dist' - AttributeError: 'list' object has no attribute 'dist' AttributeError: 'str' 对象没有属性 'dist' - AttributeError: 'str' object has no attribute 'dist' AttributeError:模块没有属性 - AttributeError: module has no attribute AttributeError:模块“ ...”没有属性“ ...” - AttributeError: module '…' has no attribute '…' AttributeError: 模块 ' ' 没有属性 ' ' - AttributeError: module ' ' has no attribute ' ' 导入 SMOTE 引发 AttributeError:模块“sklearn.metrics._dist_metrics”没有属性“DistanceMetric32” - Importing SMOTE raise AttributeError: module 'sklearn.metrics._dist_metrics' has no attribute 'DistanceMetric32' AttributeError: 'module' 对象没有属性 - AttributeError: 'module' object has no attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM