[英]Python AttributeError: 'module' object has no attribute 'DIST_L2'
[英]AttributeError: module 'math' has no attribute 'dist'
我的代碼在本地 Jupiter Notebook 中運行良好。 我嘗試在 google colab 中運行相同的代碼,但出現 AttributeError:模塊“math”沒有屬性“dist”。 下面的代碼是我項目中的幾行
import math
distance = math.dist(x, y)
更新:google colab中python的默認版本是3.7.13
更新:我發現問題是由於 python 的版本引起的。 僅在 Python 3.8 之后,才將 function dist 添加到數學模塊。
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
我在 StackOverFlow 上找到的上面的代碼here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.