【Pytorch-从一团乱麻到入门】:1、Pytorch、jupyter notebook 的安装及设置

一. pytorch安装

1、查看CUDA版本

安装pytorch之前需要确定集群的CUDA版本,根据CUDACUDA版本去pytorch官网上选择合适的版本,根据提供的conda命令行安装即可

查看CUDA版本的方式

使用nvidia-smi查询驱动版本,如图所示:

2.pytorch安装

去pytorch网址选择合适的版本,然后使用conda安装即可:

Start Locally | PyTorch

二、jupyter notebook安装及使用(linux安装浏览器版本)

编写python脚本时,使用vim直接编写会存在许多不方便之处,推荐使用jupyter notebook进行python脚本编写,暂时用到以下优点:

1)可tab补全命令;

2)可直接选择合适的环境;

3)可选择性执行某几行命令;

4)在脚本运行时可继续编写脚本;

5)对长脚本选择性隐藏;

6)可在浏览器中打开

1.jupyter notebook的安装

使用conda安装jupyter notebook即可

2.jupyter notebook安装时遇到的问题:

遇到了无法浏览器跳转页面的问题

参考:https://blog.csdn.net/weixin_34551614/article/details/113323751 解决

备注:此方法为在linux集群上安装firefox浏览器,调用的为集群上安装浏览器,实际使用时很卡,最终选择将集群的jupyter 映射到本地进行操作,详细内容可见后面3部分描述。

第一步:在linux安装浏览器,安装的为火狐浏览器

tar -xvjf Firefox-latest-x86_64.tar.bz2

然后将相应的文件ln到bin下方便直接调用

ln -s /path/01.Software/firefox/firefox /path/bin

生成jupyter_notebook_config.py文件

第二步:

使用命令 jupyter notebook --generate-config,生成 jupyter_notebook_config.py文件,附带该文件的路径。

(base) [xx@xxx ~]$ jupyter notebook --generate-config

Writing default config to: /home/xx/.jupyter/jupyter_notebook_config.py

在/home/xx/.jupyter/jupyter_notebook_config.py文件中写入:

在# c.NotebookApp.password = ''后面写入:

import webbrowser

webbrowser.register('firefox',None, webbrowser.GenericBrowser("/path/firefox/firefox"))

c.NotebookApp.browser = 'firefox'

第三步:然后再执行jupyter notebook即可

3.最终选择的将jupyternotebook映射到本地浏览器的方法说明

参考:https://blog.csdn.net/fffsolomon/article/details/103733300?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_ecpm_v1~rank_v31_ecpm-2-103733300.pc_agg_new_rank&utm_term=jupyter%E7%BD%91%E9%A1%B5%E5%BC%B9%E4%B8%8D%E5%87%BA%E6%9D%A5&spm=1000.2123.3001.4430

将jupyter映射到本地浏览器操作的方式( 本地访问Linux服务器上的jupyter notebook_机器不爱学习-CSDN博客)(最终参考使用的这个版本)

第一步:获取ipython密码并记住

(pytorch) [xx@xxx ~]$ ipython

Python 3.7.11 (default, Jul 27 2021, 14:32:16)

Type 'copyright', 'credits' or 'license' for more information

IPython 7.29.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from notebook.auth import passwd

In [2]: passwd()

Enter password:

Verify password:

Out[2]: 'argon2:$argon2id$v=19$m=10240,t=10,p=8$A154/6xNq82MNG1DSFkuLA$fwulDNATERTRAGxMbRLbAUfA'  ##记住这个密码

第二步:更改/home/xx/.jupyter/jupyter_notebook_config.py 文件中相应的配置:

c.NotebookApp.password = u'argon2:$argon2id$v=19$m=10240,t=10,p=8$A154/6xNq82MNG1DSFkuLA$fwulDNATERTRAGxMbRLbAUfA'

c.NotebookApp.allow_remote_access = True

c.NotebookApp.open_browser = False

c.NotebookApp.port = 1234   #这个可以根据自己喜欢随便定义

第三步:开放防火墙端口(若没开的话,找集群管理员开放一下)

开通方式可参考:

https://blog.csdn.net/qq_22884761/article/details/98941150?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.no_search_link)

第四步:使用jupyter notebook

在终端直接打jupyter notebook即可,粘贴http://1xx.xx.3.45:1234/到本地浏览器上使用即可。

4.根据喜好设置jupyter风格

通过命令行窗口或 Anaconda Prompt 窗口

1)安装 Jupyter 主题

pip install jupyterthemes

2)更新 Jupyter 主题 (可选)

pip install --upgrade jupyterthemes

3)查看可用的 Jupyter 主题

jt -l

4)更换 Jupyter 主题

jt -t chesterish  -f fira -fs 10 -cellw 90% -ofs 9 -dfs 9 -T -T

-t 主题 -f(字体)  -fs(字体大小) -cellw(占屏比或宽度)  -ofs(输出段的字号)  -T(显示工具栏)  -T(显示自己主机名)

5.设置jupyter 隐藏输入行

对于用Jupyter Notebook编写的python脚本,如果可以将较长的代码部分隐藏,只显示Markdown说明文本、和代码块的运行结果,便可将脚本直接用作动态分析报告。即在保持可读性的同时,可通过刷新原数据/调整代码即时生成新的报告内容。

实现显示/隐藏代码块的步骤:

1)安装jupyter_contrib_nbextentions

(Ref: https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/install.html#install-the-python-package)

conda安装命令:conda install -c conda-forge jupyter_contrib_nbextensions

python安装命令:pip install jupyter_contrib_nbextensions

2)安装jupyter_nbextentions_contributor,以便在Jupyter Notebook页面设置nbextentions

(Ref: https://github.com/Jupyter-contrib/jupyter_nbextensions_configurator)

conda安装命令:conda install -c conda-forge jupyter_nbextensions_configurator

python安装命令:pip install jupyter_nbextensions_configurator

3)安装完成后,点击Jupyter Notebook首页的Nbextensions标签,打开在Nbextensions configuration设置页面。

1)勾选Hide input(显示/隐藏选定代码块)

2)勾选Hide input all(显示/隐藏所有代码块)

参考:作者:xrdcc

链接:https://www.jianshu.com/p/3022b93bf5cd

转载公众号文章:Pytorch-从一团乱麻到入门:1、Pytorch、jupyter的安装 (qq.com)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值