|
$ J" y; m; ^1 U<p>@</p><p></p>
( M" r: ?& ?, O' ]6 L<p><strong>OS:</strong> ubuntu 20.04(虚拟机)</p>
7 Q& r& |& V5 C1 X<h1 id="一工具安装">一、工具安装</h1>. i1 X7 Q5 }. k5 F% t. F) B: c
<h2 id="11-anaconda-安装">1.1 Anaconda 安装</h2>
?" F3 s/ N# E! R<p>首先安装Anaconda ,我是去<a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/">清华大学镜像站</a>下载,版本为<br>
5 g- y! R% G1 _9 j5 D9 d4 g; x<code>Anaconda3-5.2.0-Linux-x86_64.sh</code><br>
1 F) D" T4 y$ `( p/ m$ L( n参考<a href="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>
: }% [" n2 U8 C- D安装成功测试:<br>
6 [% D3 H! `" d9 O<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102427806-11701860.png" ><br>% c" |& L- E9 O/ P, k
首先创建一个虚拟环境:</p>
0 H) X5 K3 {, G<pre><code class="language-c">conda create -n pytorch python=3.65 c- o, | ^5 g6 I$ \" D# F; C
</code></pre>
+ i, H4 o0 q7 a# ~$ q8 {$ }<p><img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102428555-1044758357.png" ><br>$ E0 f0 ^/ F7 G7 A2 p# v
输入</p>- U8 X# o" K# y0 l
<pre><code class="language-c">source activate pytorch
3 o8 ^$ [% D7 u9 p7 k6 P</code></pre>
$ ^/ P- h4 n6 @ H<p>激活环境</p>
$ t2 I4 {9 S; w, G$ L8 Y<h2 id="12-pytorch安装">1.2 Pytorch安装</h2>
: y. o' D3 G$ \4 }2 W<p>进入<a href="https://pytorch.org/get-started/locally/">官网</a>,选择合适版本安装,因为我是用的ubuntu20.04虚拟机,不支持CUDA,所以选择了CPU:<br>
$ B: v) P3 _- M5 \. f: a<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429086-588112728.png" ></p>$ w+ z$ ?/ E/ D: M8 }
<p>选择合适版本并复制Run this Command:即可进行安装(不推荐使用方法,因为下载速度很慢)。<br>) o7 u$ g4 F& F3 q# U o
安装过程可能比较缓慢,可以用以下命令(推荐)‘</p>
' @' I; ~; M0 F' X4 Y; U<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
! ?( g8 Y1 |4 Q</code></pre>
' w; S' ?7 g4 @$ y& @( C, J4 S/ |<p>注意:先进入所创建的 Pytorch虚拟环境,再输入指令进行安装。<br>; d$ @! P: W# U' F0 ]
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429678-1764231985.png" ><br>1 ~- X j% z6 z+ `% B! R( _
安装好后进行测试:<br>3 X! h; F+ ?4 t) c' ~/ ~
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102430213-1770020069.png" ></p>
" y7 S. t8 u- K3 u1 W/ O<h1 id="二编辑器安装">二、编辑器安装</h1>
5 w* a& w8 `) K6 Z, q3 o; }! I' Z<h2 id="21-pycharm安装">2.1 Pycharm安装</h2>0 S4 l7 |& E: Q
<p>官方下载地址是:<a href="https://www.jetbrains.com/pycharm/download/#section=linux">https://www.jetbrains.com/pycharm/download/#section=linux</a><br>
+ ^1 G. U) k B选择免费的社区版安装:<br>3 o# J" M# h2 V+ b- v
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102431391-2074783399.png" ><br>
9 g h; [0 |7 e1 ?下载下来就是解压,放到一个合适的文件夹下,然后添加环境变量</p>
8 w+ c5 J5 m# y: y' k. g) O- _9 \<pre><code class="language-bash">gedit .bashrc
% p8 P1 ], E# b</code></pre>
& e3 `: R: G' R% V' d. ?9 P( q<p>在最下面一行输入:</p>
( L! q* G# d E& ~# y0 C" l; T4 T7 B<pre><code class="language-c"># pycharm$ E$ u; Y! |; R, `3 |; ` d$ T' ]
alias pycharm="sh /home/jc-cao/app_download_address/Pycharm2021/pycharm-community-2021.3.1/bin/pycharm.sh"
3 r% M r" Y; q( M. u</code></pre>
( a# I; T1 m& _/ c9 n* P<p>注:将上面的路径改为自己的pycharm安装路径即可<br>
' ]2 o2 N8 f6 _( c9 o然后使配置生效</p>
/ }2 f/ h' A9 X% w6 V<pre><code class="language-c">source .bashrc
. N! v4 A7 n% o& T0 V</code></pre>
& Q1 S/ |2 g* F<p>这样在终端输入 <code>pycharm</code> 就能打开软件了<br>
" T. B2 v+ o) T1 p* L, e3 a5 _" `<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102432003-1803611031.png" ><br>
" ]' a' m/ A/ ^9 {2 R* O0 N* t接下来创建一个名为 learn_pytorch的工程:<br>6 ]6 u1 Q- P* X0 ], _; U
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433439-420704314.png" ><br>
5 ]/ H1 d" s% L' C. M6 N选择解释器为之前所创建的名为pytorch的虚拟环境的python解释器</p>
3 h* _9 ?6 r @5 }* H+ K* v0 y- l<h2 id="22-jupyter安装">2.2 Jupyter安装</h2>8 y4 P. ~0 v8 g }$ q y9 v
<p>在pytorch 虚拟环境中,输入</p>
2 W7 C; r8 f6 W+ u<pre><code class="language-c">conda install nb_conda
, q$ p9 A* f9 w; J5 h# o1 }</code></pre>
5 j; V7 [# \+ t: N7 n5 k$ H$ v<p>安装jupyter:<br>' Z4 F! v( V$ l
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433994-347380977.png" ><br>
2 K5 u1 N! v. o& h3 C安装好后输入 <code>jupyter notebook</code> 测试<br>
# z2 y; L2 H, m ]4 n6 n<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434545-226958772.png" ><br># p" O0 l6 [9 _
在jupyter中新建一个notebook,采用pytorch虚拟环境的python解释器,即可导入torch包进行使用了。<br>
/ Q' g! Y$ F% Y1 j<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434869-1058987249.png" ></p>
1 x8 J0 e+ o( b5 N% s<ul>
4 D4 ^. P% h) G( R1 W5 L3 w<li>更多技术文章和学习资料,请关注我的公众号:【集成电路设计教程】</li>3 b2 h5 A' G* w, V. `( W* {" w. v
<li>全平台统一:【雪天鱼】</li>
5 U3 P" k1 |+ n</ul>
; O' \) p5 r3 i5 S# A% P: s' l+ p L7 t
|
|