操作系统环境为:阿里云Ubuntu 18.04.4
方法一
安装前先更新
sudo apt-get update
安装numpy、pandas、matplotlib
sudo apt-get install python3-numpy
sudo apt-get install python3-pandas
sudo apt-get install python3-matplotlib
方法二
也可安装anconda。可以查看一下这篇文章。
Linux下安装anconda
方法三
使用pip安装。
先安装pip
sudo apt-get install python3-pip
利用pip安装pytorch,由于我的云服务器没有GPU(白嫖的半年云服务器,可以免费学习学习liunx系统哈哈),只能安装cpu版本。
注意:必须使用pip3安装,使用pip会安装在python2上。
pip3 install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
测试
输入python3进入python环境。
>>> import torch
>>> torch.__version__
'1.5.0+cpu'
>>> a = torch.ones(3,5)
>>> a
tensor([[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.],
[1., 1., 1., 1., 1.]])
安装jupyterlab
pip3 install jupyterlab
运行警告(忽略即可):
root@yunxingluoyun:~# jupyter lab
[I 15:27:26.556 LabApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[I 15:27:26.955 LabApp] JupyterLab extension loaded from /usr/local/lib/python3.6/dist-packages/jupyterlab
[I 15:27:26.955 LabApp] JupyterLab application directory is /usr/local/share/jupyter/lab
[C 15:27:26.957 LabApp] Running as root is not recommended. Use --allow-root to bypass.
如果本地liunx系统,使用该命令打开jupyterlab即可。
jupyter lab --allow-root
由于我的电脑是win10系统,需要远程访问服务器。
首先输入,查看配置文件位置
root@yunxingluoyun:~# jupyter notebook --generate-config --allow-root
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
root@yunxingluoyun:~# cd .jupyter
root@yunxingluoyun:~/.jupyter# ls
jupyter_notebook_config.py
接下来打开配置文件,进行配置,详见下面那篇文章。
这里我采用了远程访问服务器Jupyter Notebook的两种方法这篇文章中的第二种方法,进行文件配置。
通过Xshell远程控制打开jupyterlab
1.本地安装Xshell建立与服务器的连接
2.在Xshell的‘所有会话’找到自己连接的会话,右键‘属性’—‘SSH’—‘隧道’—‘添加’:
在打开的‘添加’窗口中添加‘侦听端口A’和‘目标端口B’,这两个端口可以一样,也可以不一样。我将端口设为8888,会有问题。
最后,在Xshell中输入:
jupyter lab --allow-root
将链接复制到本地浏览器中打开。
测试
查看之前在阿里云服务器中安装opencv和pytorch的本版。