前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >python2.7安装pytorch_PyTorch安装「建议收藏」

python2.7安装pytorch_PyTorch安装「建议收藏」

作者头像
全栈程序员站长
发布2022-09-07 15:28:52
1.2K0
发布2022-09-07 15:28:52
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

这个系列写了好几篇文章,这是相关文章的索引,仅供参考:

以下是相关深度学习工具包的安装,包括Tensorflow, PyTorch, Torch等:

首先安装libcupti-dev

sudo apt-get install libcupti-dev

然后用 virtualenv 方式安装 Tensorflow(当前是1.4版本)

sudo apt-get install python-pip python-dev python-virtualenv

mkdir tensorflow

cd tensorflow

virtualenv –system-site-packages venv

source venv/bin/activate

pip install –upgrade tensorflow-gpu

测试GPU:

Python 2.7.12 (default, Nov 19 2016, 06:48:10)

[GCC 5.4.0 20160609] on linux2

Type “help”, “copyright”, “credits” or “license” for more information.

>>> import tensorflow as tf

>>> sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

2017-10-24 20:37:24.290049: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 0 with properties:

name: GeForce GTX 1080 Ti

major: 6 minor: 1 memoryClockRate (GHz) 1.6575

pciBusID 0000:01:00.0

Total memory: 10.91GiB

Free memory: 10.52GiB

2017-10-24 20:37:24.387363: I tensorflow/core/common_runtime/gpu/gpu_device.cc:955] Found device 1 with properties:

name: GeForce GTX 1080 Ti

major: 6 minor: 1 memoryClockRate (GHz) 1.6575

pciBusID 0000:02:00.0

Total memory: 10.91GiB

Free memory: 10.76GiB

2017-10-24 20:37:24.388168: I tensorflow/core/common_runtime/gpu/gpu_device.cc:976] DMA: 0 1

2017-10-24 20:37:24.388176: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 0: Y Y

2017-10-24 20:37:24.388179: I tensorflow/core/common_runtime/gpu/gpu_device.cc:986] 1: Y Y

2017-10-24 20:37:24.388186: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0)

2017-10-24 20:37:24.388189: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1045] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0)

Device mapping:

/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0

/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0

2017-10-24 20:37:24.449867: I tensorflow/core/common_runtime/direct_session.cc:300] Device mapping:

/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:01:00.0

/job:localhost/replica:0/task:0/gpu:1 -> device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0

>>>

首先在PyTorch的官网下载对应的pip安装文件:

8d7bb8970b8af921cef93d396bb3b157.png
8d7bb8970b8af921cef93d396bb3b157.png

然后用virtualenv的方式安装,非常方便:

mkdir pytorch

cd pytorch/

virtualenv venv

source venv/bin/activate

pip install /path/to/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl

pip install torchvision

git clone https://github.com/torch/distro.git ~/torch –recursive

cd ~/torch; bash install-deps;

./install.sh

如无意外,可以顺利安装,如果遇到了如下两个问题,可按下述方法修改:

1) 执行./install.sh时出现Moses>=1.错误

Missing dependencies for nn:moses >= 1.,有时候执行./install.sh时,会出现这个问题。

用这个方法解决:

sudo apt install luarocks

sudo luarocks install moses

2) install.sh 过程中提示“error — unsupported GNU version! gcc versions later than 5 are not supported!”

ubuntu17.04自带gcc 6.x 版本,所以降级安装gcc 4.9版本解决问题:

sudo apt-get install g++-4.9

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20

sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.9 20

成功执行安装脚本后后提示:

Do you want to automatically prepend the Torch install location

to PATH and LD_LIBRARY_PATH in your /home/yourpath/.bashrc? (yes/no)

[yes] >>>

yes

安装脚本会自动将torch的安装路径写入到 .bashrc里,然后输入 th试试:

cc8f61d09fee464542a4dbb61c51803e.png
cc8f61d09fee464542a4dbb61c51803e.png

如果你想用Lua5.2替代LuaJIT的方式安装Torch(If you want to install torch with Lua 5.2 instead of LuaJIT, simply run),可按如下方式安装:

git clone https://github.com/torch/distro.git torch –recursive

cd torch

# clean old torch installation

./clean.sh

在 ~/.bashrec中设置lua的环境:

TORCH_LUA_VERSION=LUA52

并执行 source ~/.bashrc, 然后运行:

./install.sh

遇到第一个问题:

cmake: not found

安装cmake解决:

sudo apt-get install cmake

第二个问题:

readline.c:8:31: fatal error: readline/readline.h: 没有那个文件或目录

安装libreadine-dev解决:

sudo apt-get install libreadline-dev

第三个问题:安装过程依然提示“error — unsupported GNU version! gcc versions later than 5 are not supported!”

ubuntu17.04自带gcc 6.x 版本,所以降级安装gcc 4.9版本解决问题:

sudo apt-get install g++-4.9

sudo update-alternatives –install /usr/bin/gcc gcc /usr/bin/gcc-4.9 20

sudo update-alternatives –install /usr/bin/g++ g++ /usr/bin/g++-4.9 20

安装完毕依然会提示:

Not updating your shell profile.

You might want to

add the following lines to your shell profile:

. /home/textminer/torch/torch/install/bin/torch-activate

在 ~/.profile 文件末尾加上这行 “. /home/textminer/torch/torch/install/bin/torch-activate ” 并执行 source ~/.profile,然后输入 th试试。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/152772.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年6月2,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档