|
' t& u! J4 |- p5 I% l2 i1 T2 }<p>@</p><p></p>' U2 m& [3 `' D# G
<p><strong>OS:</strong> ubuntu 20.04(虚拟机)</p>
2 h' C$ r r. f: g5 z<h1 id="一工具安装">一、工具安装</h1>: h7 J4 \, `+ ?6 ]
<h2 id="11-anaconda-安装">1.1 Anaconda 安装</h2>7 ~8 Q2 I3 i5 c% w6 F4 ~
<p>首先安装Anaconda ,我是去<a href="https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/">清华大学镜像站</a>下载,版本为<br>
' G' _, i1 W' i<code>Anaconda3-5.2.0-Linux-x86_64.sh</code><br>
" O1 b( G9 l7 \! F5 S参考<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>
( j6 j- ]- U; t t5 Q安装成功测试:<br>6 A4 B& k; d& @, [5 @7 ~
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102427806-11701860.png" ><br>$ m! [9 v0 f% M, ?8 N
首先创建一个虚拟环境:</p>, B; M/ M# e# v* p
<pre><code class="language-c">conda create -n pytorch python=3.6
2 \) h3 V: k) z8 J j</code></pre>
; e4 z8 q7 i7 H. @<p><img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102428555-1044758357.png" ><br>4 [: P& w) O, ^6 R
输入</p>
" F# x0 y4 C( k) x$ u<pre><code class="language-c">source activate pytorch# I7 B! P0 n S. ~/ l0 S4 g% N
</code></pre>/ q$ r5 v+ m/ l! J7 V
<p>激活环境</p>* F. K1 K$ z4 B5 {: V2 [& ?& ?
<h2 id="12-pytorch安装">1.2 Pytorch安装</h2>2 s7 {7 [0 g: X
<p>进入<a href="https://pytorch.org/get-started/locally/">官网</a>,选择合适版本安装,因为我是用的ubuntu20.04虚拟机,不支持CUDA,所以选择了CPU:<br>
6 m% D+ L0 P7 R<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429086-588112728.png" ></p>
# t) @7 W' w6 M' c( F- @0 b* H. v<p>选择合适版本并复制Run this Command:即可进行安装(不推荐使用方法,因为下载速度很慢)。<br>; p) }' G w# k# _( L5 S
安装过程可能比较缓慢,可以用以下命令(推荐)‘</p>5 C0 R/ q4 ~. L
<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
! h0 y+ @6 W4 q% V: e</code></pre>
; R8 X( s; @! G8 V<p>注意:先进入所创建的 Pytorch虚拟环境,再输入指令进行安装。<br>3 G+ ^. K: y0 |* l9 M' l3 K
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102429678-1764231985.png" ><br>
* L( n1 z* G7 s% y# p安装好后进行测试:<br>
% f0 M+ j' _9 D, r' q% C<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102430213-1770020069.png" ></p>% f6 r( B# ] b/ `6 ?
<h1 id="二编辑器安装">二、编辑器安装</h1>
7 A9 I: d' @" N. U2 l<h2 id="21-pycharm安装">2.1 Pycharm安装</h2>6 L3 r4 m1 K# ]: z8 L' T
<p>官方下载地址是:<a href="https://www.jetbrains.com/pycharm/download/#section=linux">https://www.jetbrains.com/pycharm/download/#section=linux</a><br># h" U0 l/ u2 N( R
选择免费的社区版安装:<br># |; S; I! v) x7 T8 D k* |* F
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102431391-2074783399.png" ><br>
. q/ O$ m* ~* n8 y$ ]下载下来就是解压,放到一个合适的文件夹下,然后添加环境变量</p>! v9 v/ F$ Q+ r+ \# u
<pre><code class="language-bash">gedit .bashrc% Z* u& y6 @, I9 S6 O4 B
</code></pre>
, Y6 z+ a! G& D. _' U( ]<p>在最下面一行输入:</p>9 \3 z2 ?% X: g' Y! O- E
<pre><code class="language-c"># pycharm
( B" V, [; P: j, ealias pycharm="sh /home/jc-cao/app_download_address/Pycharm2021/pycharm-community-2021.3.1/bin/pycharm.sh"
5 M2 K9 {7 O' ?5 y</code></pre>% G9 t5 o7 Z; J/ g4 y9 ^, y
<p>注:将上面的路径改为自己的pycharm安装路径即可<br>
: Q1 H" e" g. a$ k/ |# z然后使配置生效</p>/ V* x4 u4 i8 N* T, i7 o$ b \' T
<pre><code class="language-c">source .bashrc
3 ?5 l" y& f/ y) R' q* |3 d</code></pre>, L# c9 Z7 V2 p7 V# l
<p>这样在终端输入 <code>pycharm</code> 就能打开软件了<br>. y, F4 y8 E9 T" H0 H2 x
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102432003-1803611031.png" ><br>
0 z ]( t8 V! a) o( M1 x$ [接下来创建一个名为 learn_pytorch的工程:<br>- X0 o- r! s6 e
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433439-420704314.png" ><br>
/ _0 z, Y' J0 K) A9 H选择解释器为之前所创建的名为pytorch的虚拟环境的python解释器</p>
4 i9 m Z; |. h<h2 id="22-jupyter安装">2.2 Jupyter安装</h2>
5 ]" \7 ^; {& [4 s4 r, I% ]' a1 Q* E<p>在pytorch 虚拟环境中,输入</p>4 R( N- n& Q/ \/ C6 N& X! _
<pre><code class="language-c">conda install nb_conda9 W9 N0 Q% A3 y4 ~9 a& C* o+ n
</code></pre>( D9 S- Z4 H. o% X6 R" j: e" I0 p0 J
<p>安装jupyter:<br>
1 p: \8 e7 `- R" K<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102433994-347380977.png" ><br>
2 C0 Q; z6 I' m5 ^安装好后输入 <code>jupyter notebook</code> 测试<br>9 l( Y2 I1 ^3 s8 j
<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434545-226958772.png" ><br>
4 v7 ~+ N2 k) H+ h在jupyter中新建一个notebook,采用pytorch虚拟环境的python解释器,即可导入torch包进行使用了。<br>
$ D- `: S" F# z, e. O<img src="https://img2022.cnblogs.com/other/1772025/202202/1772025-20220212102434869-1058987249.png" ></p>
9 ~! p' A& u) N) [: o+ g0 l<ul>% r0 R% M2 n9 e6 s! ]
<li>更多技术文章和学习资料,请关注我的公众号:【集成电路设计教程】</li>
+ F$ l, R* W3 ^, c<li>全平台统一:【雪天鱼】</li>! V4 g& F5 p$ [3 r; M1 b2 q
</ul>
$ l9 O) B, N" n7 @
& @2 x9 I5 _, b1 S& i% ^* n |
|