日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

02/03_Pytorch安装、Conda安装Pythorch,换源、pytorch官网、验证、安装jupyter、卸载、安装、启动jupyter、配置Jupyter notebook、使用

發布時間:2024/9/27 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 02/03_Pytorch安装、Conda安装Pythorch,换源、pytorch官网、验证、安装jupyter、卸载、安装、启动jupyter、配置Jupyter notebook、使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.2.Pytorch安裝

1.2.1.Conda安裝Pythorch,換源

1 conda添加清華鏡像源
查看源

conda config --show-sources

由于從官方的conda源中下載速度過于緩慢,我們需要配置清華鏡像源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/ conda config --set show_channel_urls yes

為了保險起見,建議同時添加第三方conda源:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --set show_channel_urls yes

2 創建并進入虛擬環境

conda create -n pytorchconda activate pytorch

1.2.2.pytorch官網

官網開始學習的地址:https://pytorch.org/get-started/locally/;點擊相關的內容,可以看到如下的內容:

在圖片的最下方可以看到Run this Command,這個就是要運行的命令。如上顯示的內容(注意:如果下載的慢,就使用-i命令指定清華的源):

pip install torch===1.7.1 torchvision===0.8.2 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple

選擇另外的,可能會出現類似:

NOTE: Python 3.9 users will need to add '-c=conda-forge' for installation conda install pytorch torchvision torchaudio cudatoolkit=10.1 -c pytorch (但是這里一定要注意,去掉-c pytorch,安裝的時候才會默認從清華源下載相應的包,因此這里用命令行) conda install pytorch torchvision torchaudio cudatoolkit=10.1

接著等待安裝成功就好了。

1.2.3.驗證

為了確保PyTorch被正確安裝,我們可以運行樣例PyTorch代碼來驗證安裝。這里我們將構造一個隨機初始化張量。

# -*- coding: UTF-8 -*-import torch x = torch.rand(5,3) print(x)print(torch.__version__)

結果應該是:

tensor([[0.2966, 0.2469, 0.2908],[0.1125, 0.0722, 0.1402],[0.4008, 0.0162, 0.7278],[0.3127, 0.6203, 0.2005],[0.2571, 0.6653, 0.8652]]) 1.7.1+cpu

1.3.安裝jupyter

參考博文:https://blog.csdn.net/yu1014745867/article/details/84191485

Jupyter Notebook(此前被稱為IPython notebook)是一個交互式筆記本,支持運行40多種編程語言。

Jupyter Notebook的本質是一個為web應用程序,便于創建和共享程序文檔,支持實時代碼,數學方程,可視化和markdown

1.3.1.卸載、安裝、啟動jupyter

打開Anaconda PowerShell,然后輸入:

pip install jupyter

執行效果如下:

(base) PS C:\Users\toto> pip install jupyter Requirement already satisfied: jupyter in d:\installed\anaconda3\lib\site-packages (1.0.0) Requirement already satisfied: notebook in d:\installed\anaconda3\lib\site-packages (from jupyter) (6.0.1) Requirement already satisfied: jupyter-console in d:\installed\anaconda3\lib\site-packages (from jupyter) (6.0.0) Requirement already satisfied: ipywidgets in d:\installed\anaconda3\lib\site-packages (from jupyter) (7.5.1) Requirement already satisfied: nbconvert in d:\installed\anaconda3\lib\site-packages (from jupyter) (5.6.0) Requirement already satisfied: qtconsole in d:\installed\anaconda3\lib\site-packages (from jupyter) (4.5.5) Requirement already satisfied: ipykernel in d:\installed\anaconda3\lib\site-packages (from jupyter) (5.1.2) Requirement already satisfied: nbformat in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (4.4.0) Requirement already satisfied: jupyter-client>=5.3.1 in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (5.3.3) Requirement already satisfied: prometheus-client in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (0.7.1) Requirement already satisfied: pyzmq>=17 in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (18.1.0) Requirement already satisfied: jupyter-core>=4.4.0 in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (4.5.0) Requirement already satisfied: terminado>=0.8.1 in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (0.8.2) Requirement already satisfied: tornado>=5.0 in d:\installed\anaconda3\lib\site-packages (from notebook->jupyter) (6.0.3)


啟動jupyter

(base) PS C:\Users\toto> jupyter notebook

界面效果:

(base) PS C:\Users\toto> jupyter notebook [I 12:28:21.470 NotebookApp] The port 8888 is already in use, trying another port. [I 12:28:21.533 NotebookApp] JupyterLab extension loaded from D:\installed\Anaconda3\lib\site-packages\jupyterlab [I 12:28:21.533 NotebookApp] JupyterLab application directory is D:\installed\Anaconda3\share\jupyter\lab [I 12:28:21.536 NotebookApp] Serving notebooks from local directory: C:\Users\toto [I 12:28:21.536 NotebookApp] The Jupyter Notebook is running at: [I 12:28:21.537 NotebookApp] http://localhost:8889/?token=c5fadcb59ade1027bfa184f07ca753f4acb13185241fa6be [I 12:28:21.537 NotebookApp] or http://127.0.0.1:8889/?token=c5fadcb59ade1027bfa184f07ca753f4acb13185241fa6be [I 12:28:21.537 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 12:28:21.760 NotebookApp]To access the notebook, open this file in a browser:file:///C:/Users/toto/AppData/Roaming/jupyter/runtime/nbserver-12424-open.htmlOr copy and paste one of these URLs:http://localhost:8889/?token=c5fadcb59ade1027bfa184f07ca753f4acb13185241fa6beor http://127.0.0.1:8889/?token=c5fadcb59ade1027bfa184f07ca753f4acb13185241fa6be [I 12:31:25.070 NotebookApp] 302 GET /?token=c5fadcb59ade1027bfa184f07ca753f4acb13185241fa6be (127.0.0.1) 1.00ms [I 12:31:32.990 NotebookApp] Creating new file in [I 12:32:10.919 NotebookApp] Creating new notebook in [I 12:32:13.228 NotebookApp] Kernel started: 082a09a5-e52a-40f2-904f-3870a737fdc6 [I 12:33:14.333 NotebookApp] Saving file at /Untitled1.ipynb

1.3.2.配置Jupyter notebook

1、命令行輸入命令:

(base) PS C:\Users\toto> jupyter notebook --generate-config Writing default config to: C:\Users\toto\.jupyter\jupyter_notebook_config.py (base) PS C:\Users\toto>

2、打開”.jupyter”文件夾,可以看到里面有個配置文件

3、修改jupyter_notebook_config.py配置文件
找到”c.NotebookApp.notebook_dir=…”,把路徑改成自己的工作目錄。


4、配置完成后,重新jupyter notebook啟動即可
5、啟動方式:
6、Anaconda–>Anaconda Prompt -->命令行輸入:

jupyter notebook 7、啟動后默認的打開路徑就是之前配置好的路徑啦。

1.3.3.使用

1、運行jupyter notebook
2、需要新建python文件的話,點擊New–>Python3

3、新建后,頁面顯示如下,菜單欄也出來了,就可以開始編寫文件啦。

與50位技術專家面對面20年技術見證,附贈技術全景圖

總結

以上是生活随笔為你收集整理的02/03_Pytorch安装、Conda安装Pythorch,换源、pytorch官网、验证、安装jupyter、卸载、安装、启动jupyter、配置Jupyter notebook、使用的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。