02/03_Pytorch安装、Conda安装Pythorch,换源、pytorch官网、验证、安装jupyter、卸载、安装、启动jupyter、配置Jupyter notebook、使用
1.2.Pytorch安裝
1.2.1.Conda安裝Pythorch,換源
1 conda添加清華鏡像源
查看源
由于從官方的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 yes2 創建并進入虛擬環境
conda create -n pytorchconda activate pytorch1.2.2.pytorch官網
官網開始學習的地址:https://pytorch.org/get-started/locally/;點擊相關的內容,可以看到如下的內容:
在圖片的最下方可以看到Run this Command,這個就是要運行的命令。如上顯示的內容(注意:如果下載的慢,就使用-i命令指定清華的源):
選擇另外的,可能會出現類似:
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+cpu1.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 [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.ipynb1.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 -->命令行輸入:
1.3.3.使用
1、運行jupyter notebook
2、需要新建python文件的話,點擊New–>Python3
3、新建后,頁面顯示如下,菜單欄也出來了,就可以開始編寫文件啦。
總結
以上是生活随笔為你收集整理的02/03_Pytorch安装、Conda安装Pythorch,换源、pytorch官网、验证、安装jupyter、卸载、安装、启动jupyter、配置Jupyter notebook、使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 01_Win10下CUDA的安装、查看并
- 下一篇: 澳门买黄金注意事项