安裝好 PyTorch1.5.0 之后,在 Anaconda Prompt 中激活新創建的環境變數之后,import torch 并 列印 torch 的版本沒有問題,說明 PyTorch 已經安裝成功,但是打開 Jupyter Notebook 后 import torch 卻提示 “No module named torch”
報錯如下:

我們還需要在這個環境安裝 jupyter notebook 的一系列依賴庫
conda install jupyter
接著在這個環境變數中安裝nb_conda(關鍵)
conda install nb_conda
重啟 jupyter notebook 后再進入,選擇對應的 Kernel 新建檔案即可:

import torch 可以正常使用了

參考了:
- 安裝PyTorch后jupyter notebook中仍出現"No module named torch"
- Windows下用pip安裝pytorch,在jupyter notebook中無法引入問題的解決
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/435447.html
標籤:AI
