跟李沐學深度學習系列-08線型迴歸問題解決From d2l import torch as d2l 報錯問題
阿新 • • 發佈:2022-04-01
From d2l import torch as d2l 報錯
執行環境:python3.8 jupyter notebook Windows
報錯:SyntaxError: invalid syntax
解決:d2l裡的l是英文字母L的小寫l不是數字1,並且也不要漏掉老師的任何一行程式碼,注意一下自己的Python版本是否是3.x
報錯:no module named d2l
解決:
首先在jupyter notebook 中輸入:!pip install -U d2l
顯示requirement already satisfied
退出jupyter note book
在cmd中輸入ipython
->import d2l
->d2l._file_
這個時候會出現一些路徑,在工作路徑下搜尋d2l包失敗,說明你要將d2l包放入此路徑
我的是在C:使用者/asus/appdata/local/programs/python/python38/Lib
將d2l資料夾放於此路徑下
此時執行出現新的錯誤:no module named 'torchvision'
如果直接在jupyter notebook中輸入pip install torchvision,會出現 yntaxError: invalid syntax錯誤
退出jupyter notebook
在cmd中輸入pip3 install torchvision
jupyter notebook的安裝和使用參考:Jupyter Notebook介紹、安裝及使用教程 - 知乎 (zhihu.com)