Ubuntu16.04安装pytorch经验整理

之前没接触过pytorch,python也可以算是零基础。安装之前看了一些经验贴,决定自己把安装步骤和过程中遇到的问题以及解决方法捋一遍,就当写日记啦。另外感谢前辈们的分享与指点。

Ubuntu16.04自带python 2.7.12 和python 3.5.2,不需要自己装python

Ubuntu16.04安装pytorch经验整理_第1张图片

第一步:安装pip3

sudo apt-get install python3-pip

顺便安装numpy

pip3 install numpy

然后会提示你更新pip的版本,于是我就选择更新了

pip3 install --upgrade pip

 

第二步:配置pip使用的镜像源

----------------------------------------------------------------------------------------------------------------------

附:

国内镜像源列表

豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

------------------------------------------------------------------------------------------------------------------------

参照经验贴,采用ailiyun镜像

运行命令:

cd ~/.pip

如果不存在该文件夹则:

mkdir ~/.pip
cd ~/.pip
touch pip.conf
gedit pip.conf

此时会跳出pip.conf窗口,在pip.conf中添加以下内容:

[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

点击右下角的保存即可

第三步:安装pytorch

运行命令:

pip install torch torchvision

下载速度还挺快的,但是download完成之后提示安装指令的权限不够(忘记截图了),提示如下:

Could not install packages due to an EnvironmentError: Permission denied: '/usr/local/lib/python3.5/dist-packages/pylab.py' Consider using the `--user` option or check the permissions.


加上--user真的就成功了,运行命令:

pip install torch torchvision --user

结果如图:

Ubuntu16.04安装pytorch经验整理_第2张图片

第四步:测试pytorch是否安装成功

在终端输入

python3(注意是输入python3,如果只输入python,会默认是python2,当然,之后你也可以自己更改python的默认版本)

import torch

import torchvision

结果如图:

Ubuntu16.04安装pytorch经验整理_第3张图片

显示如图应该就算安装成功了。

希望对你有帮助。

 


---------------------

参考博文信息如下
作者:持久决心  
来源:CSDN  
原文:https://blog.csdn.net/u013832707/article/details/80076917  
版权声明:本文为博主原创文章,转载请附上博文链接!

你可能感兴趣的:(Ubuntu16.04安装pytorch经验整理)