PyTorch深度学习入门笔记(一)PyTorch环境配置及安装
<p>@</p><p></p>
<p><strong>OS:</strong> ubuntu 20.04(虚拟机)</p>
<h1 id="一工具安装">一、工具安装</h1>
<h2 id="11-anaconda-安装">1.1 Anaconda 安装</h2>
<p>首先安装Anaconda ,我是去<ahref="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/">清华大学镜像站</a>下载,版本为<br>
<code>Anaconda3-5.2.0-Linux-x86_64.sh</code><br>
参考<ahref="https://blog.csdn.net/m0_50117360/article/details/108403586?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164187185416780357286476%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164187185416780357286476&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-108403586.pc_search_insert_ulrmf&utm_term=ubuntu20.04%E5%AE%89%E8%A3%85anaconda&spm=1018.2226.3001.4187">这篇CSDN博客</a>安装好。<br>
安装成功测试:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102427806-11701860.png" ><br>
首先创建一个虚拟环境:</p>
<pre><code class="language-c">conda create -n pytorch python=3.6
</code></pre>
<p><img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102428555-1044758357.png" ><br>
输入</p>
<pre><code class="language-c">source activate pytorch
</code></pre>
<p>激活环境</p>
<h2 id="12-pytorch安装">1.2 Pytorch安装</h2>
<p>进入<ahref="https://pytorch.org/get-started/locally/">官网</a>,选择合适版本安装,因为我是用的ubuntu20.04虚拟机,不支持CUDA,所以选择了CPU:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429086-588112728.png" ></p>
<p>选择合适版本并复制Run this Command:即可进行安装(不推荐使用方法,因为下载速度很慢)。<br>
安装过程可能比较缓慢,可以用以下命令(推荐)‘</p>
<pre><code class="language-c">pip3 --default-timeout=1000 install --index-url https://mirrors.aliyun.com/pypi/simple torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html
</code></pre>
<p>注意:先进入所创建的 Pytorch虚拟环境,再输入指令进行安装。<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429678-1764231985.png" ><br>
安装好后进行测试:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102430213-1770020069.png" ></p>
<h1 id="二编辑器安装">二、编辑器安装</h1>
<h2 id="21-pycharm安装">2.1 Pycharm安装</h2>
<p>官方下载地址是:<ahref="https://www.jetbrains.com/pycharm/download/#section=linux">https://www.jetbrains.com/pycharm/download/#section=linux</a><br>
选择免费的社区版安装:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102431391-2074783399.png" ><br>
下载下来就是解压,放到一个合适的文件夹下,然后添加环境变量</p>
<pre><code class="language-bash">gedit .bashrc
</code></pre>
<p>在最下面一行输入:</p>
<pre><code class="language-c"># pycharm
alias pycharm="sh /home/jc-cao/app_download_address/Pycharm2021/pycharm-community-2021.3.1/bin/pycharm.sh"
</code></pre>
<p>注:将上面的路径改为自己的pycharm安装路径即可<br>
然后使配置生效</p>
<pre><code class="language-c">source .bashrc
</code></pre>
<p>这样在终端输入 <code>pycharm</code> 就能打开软件了<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102432003-1803611031.png" ><br>
接下来创建一个名为 learn_pytorch的工程:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433439-420704314.png" ><br>
选择解释器为之前所创建的名为pytorch的虚拟环境的python解释器</p>
<h2 id="22-jupyter安装">2.2 Jupyter安装</h2>
<p>在pytorch 虚拟环境中,输入</p>
<pre><code class="language-c">conda install nb_conda
</code></pre>
<p>安装jupyter:<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433994-347380977.png" ><br>
安装好后输入 <code>jupyter notebook</code> 测试<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434545-226958772.png" ><br>
在jupyter中新建一个notebook,采用pytorch虚拟环境的python解释器,即可导入torch包进行使用了。<br>
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434869-1058987249.png" ></p>
<ul>
<li>更多技术文章和学习资料,请关注我的公众号:【集成电路设计教程】</li>
<li>全平台统一:【雪天鱼】</li>
</ul>
页:
[1]