|
|
/ Q2 j1 G- }+ }$ D<p>@</p><p></p>: q* C# ~. n. c" z
<p><strong>OS:</strong> ubuntu 20.04(虚拟机)</p>0 d! r0 }1 j; {6 x- @
<h1 id="一工具安装">一、工具安装</h1>
0 i9 Y# j4 `( K9 ]! ^2 {6 q# @<h2 id="11-anaconda-安装">1.1 Anaconda 安装</h2>
& ^1 @) v" j7 \1 _<p>首先安装Anaconda ,我是去<a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/">清华大学镜像站</a>下载,版本为<br>
7 n( ^; L/ p6 ^" m. O% u+ q6 p+ @$ _<code>Anaconda3-5.2.0-Linux-x86_64.sh</code><br>4 p8 J& M2 }* \
参考<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>2 W& f. h: H+ {9 K5 @. J2 M
安装成功测试:<br>
' s( K4 G0 J" e4 q8 k: o2 T<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102427806-11701860.png" ><br>9 h& B" u6 {( }' D+ w
首先创建一个虚拟环境:</p>
3 l% z. d0 O0 Z2 `! K! r<pre><code class="language-c">conda create -n pytorch python=3.6
; t: r8 r* L: i</code></pre># j: @! o- j/ t% D. Z
<p><img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102428555-1044758357.png" ><br>
. c3 X5 x) j- u! G* l输入</p>. e; u" `+ |$ y0 [! Q
<pre><code class="language-c">source activate pytorch& }! V- |7 O3 b) C8 z y% M" m3 ~
</code></pre> {, J) b# t% I$ f) [* X6 q
<p>激活环境</p>9 \3 h2 M; ~% s; q( M1 _
<h2 id="12-pytorch安装">1.2 Pytorch安装</h2>
3 K" n6 b) p9 l3 g1 W6 m0 @% O<p>进入<a href="https://pytorch.org/get-started/locally/">官网</a>,选择合适版本安装,因为我是用的ubuntu20.04虚拟机,不支持CUDA,所以选择了CPU:<br> R" Y$ C7 s/ R' [6 V
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429086-588112728.png" ></p>
$ g5 l& g0 {+ ~3 M+ S<p>选择合适版本并复制Run this Command:即可进行安装(不推荐使用方法,因为下载速度很慢)。<br># S/ h. J' @, B* b" d
安装过程可能比较缓慢,可以用以下命令(推荐)‘</p>) g* i; z: V- d. F6 c
<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.html6 `# x! W* }5 R( g& y) U8 P
</code></pre>" m; t6 ]0 A- N
<p>注意:先进入所创建的 Pytorch虚拟环境,再输入指令进行安装。<br>
; n5 X# b+ W. j2 O9 l ~' e! U<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429678-1764231985.png" ><br>, G% Y7 i* D1 }' N
安装好后进行测试:<br>
3 ^2 @. K1 V4 ?8 X' M<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102430213-1770020069.png" ></p>9 N, a4 p5 H$ d
<h1 id="二编辑器安装">二、编辑器安装</h1>
, d' |6 Y; ]9 M. y<h2 id="21-pycharm安装">2.1 Pycharm安装</h2>
) A) z5 U1 O; o<p>官方下载地址是:<a href="https://www.jetbrains.com/pycharm/download/#section=linux">https://www.jetbrains.com/pycharm/download/#section=linux</a><br>' z, @5 y+ A/ ~4 b& ^2 T+ s
选择免费的社区版安装:<br>: r" a1 h0 T1 W
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102431391-2074783399.png" ><br>
$ ?6 @+ E! W0 [4 g3 F8 h! ^7 F下载下来就是解压,放到一个合适的文件夹下,然后添加环境变量</p>
2 e% G$ X$ O9 x<pre><code class="language-bash">gedit .bashrc4 v1 Q+ V9 y2 T( Q* G
</code></pre>+ n; S( L# G! }/ d. A9 K. w( N
<p>在最下面一行输入:</p>
- o. ?4 r' L% P$ n y<pre><code class="language-c"># pycharm
4 [! b) J9 g* ^" V4 \1 E6 y1 U7 d' Qalias pycharm="sh /home/jc-cao/app_download_address/Pycharm2021/pycharm-community-2021.3.1/bin/pycharm.sh"
, K! H# {& {+ z4 S2 l7 m i</code></pre>0 c {* @4 G7 ~6 i# V( l, e- t
<p>注:将上面的路径改为自己的pycharm安装路径即可<br>
8 g5 n, s# _: \& A' h" b4 c2 x; O* Q然后使配置生效</p>
5 u; @) L. a ?9 u, t: e; h. _<pre><code class="language-c">source .bashrc
# j3 h- K- j `: i& C2 i" q3 U</code></pre>
& I7 c' H; i1 R1 `1 V3 f0 G' c<p>这样在终端输入 <code>pycharm</code> 就能打开软件了<br>
; h/ o! ]5 u9 \8 P; K* ?8 ] ]2 {<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102432003-1803611031.png" ><br>
8 H, E! @# i8 D) j+ F接下来创建一个名为 learn_pytorch的工程:<br>
' p# k9 @8 V" j) B" i% ~<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433439-420704314.png" ><br>
' R+ t! ~# ~. }' O选择解释器为之前所创建的名为pytorch的虚拟环境的python解释器</p>
; a: J' {9 T0 c, t( S$ o8 D<h2 id="22-jupyter安装">2.2 Jupyter安装</h2>& R, _5 Z8 \2 k1 X5 I T% M
<p>在pytorch 虚拟环境中,输入</p>
1 S. {% a( x) K9 H# \, P<pre><code class="language-c">conda install nb_conda5 T) P. j( c# ?( s f# |, A" P$ A
</code></pre>
$ P& s) O. D8 ?) d8 o. S2 p<p>安装jupyter:<br>
. v4 O% t; F; c6 a<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433994-347380977.png" ><br>
( n7 O) L7 Z- W. t8 ~! g% P安装好后输入 <code>jupyter notebook</code> 测试<br>
' I& g6 O& j3 N<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434545-226958772.png" ><br>. C4 ~) ?( z! d$ j/ {; N
在jupyter中新建一个notebook,采用pytorch虚拟环境的python解释器,即可导入torch包进行使用了。<br>6 k$ h0 Y. ~" z2 x$ M
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434869-1058987249.png" ></p>
7 `5 Z" {. W5 H- E+ O) u* N6 B<ul>; |' F& W- N/ X. e8 Q. I+ V0 \( }( c
<li>更多技术文章和学习资料,请关注我的公众号:【集成电路设计教程】</li>1 |: r) {8 m: K. w1 |: a" e7 f
<li>全平台统一:【雪天鱼】</li>& d0 _! w, y# g) \1 Y7 G, E) L
</ul>& ?/ E) s, s, \* A
' C4 t5 q6 t* [$ U8 L5 x
|
|