ubuntu安装tensorflow(cpu版)/Pytorch(cpu版)教程

准备

在完成系统安装后,https://blog.csdn.net/woshigaowei5146/article/details/125411831?spm=1001.2014.3001.5501

下载anaconda:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/

安装Anaconda3

下载好后,到下载路径。

bash Anaconda3-5.3.1-Linux-x86_64.sh

配置环境变量

sudo gedit ~/.bashrc

在最后一行中加入自己安装的anaconda下bin的路径:

#set Anaconda3 environment
export PATH="/home/zlt/anaconda3/bin:$PATH"

保存关闭文件后,使其生效:

source ~/.bashrc

输入python,验证。
在这里插入图片描述

安装Tensorflow

用conda新建一个python版本为3.6的虚拟环境。

conda create -n tensorflow python=3.6

激活虚拟环境

source activate tensorflow

安装tensorflow,注意没有GPU的不要装GPU版本,否则系统报错。

(tensorflow)$ pip install --ignore-installed --upgrade tfBinaryURL 

其中 tfBinaryURL 是 TensorFlow Python 包的 URL。例如,如下命令安装了仅支持 CPU 的 Python 3.4 版本下的 TensorFlow:

(tensorflow)$ pip install --ignore-installed --upgrade \
https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp34-cp34m-linux_x86_64.whl 

我用的命令:

pip install --ignore-installed --upgrade \https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl

如果安装速度慢,可换源或下载好后安装。

tensorflow对应的python版本清单:

https://tensorflow.google.cn/install/source_windows#cpu

其他版本:

Python 2.7 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp27-none-linux_x86_64.whl
支持 GPU:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp27-none-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.4 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp34-cp34m-linux_x86_64.whl
支持 GPU:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp34-cp34m-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.5 支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp35-cp35m-linux_x86_64.whl
GPU 支持:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp35-cp35m-linux_x86_64.whl
注意 GPU 支持需要符合 NVIDIA 对运行 GPU 支持版本的 TensorFlow 的要求 的软硬件要求。

Python 3.6 仅支持 CPU:

https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.8.0-cp36-cp36m-linux_x86_64.whl
GPU 支持:

https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.8.0-cp36-cp36m-linux_x86_64.whl

我之前估计是用了pip install --upgrade tensorflow命令,导致开机出现了错误:amdgpu unable to locate a bios ro。

验证安装

先看看自己的tensorflow版本,可以看到我安装版本的是1.3.0

pip list

在这里插入图片描述
输入python来运行:

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))

安装Pytorch

进入 Pytorch 官网。下滑找到配置列表,按照图示参数进行选择。
https://pytorch.org/
在这里插入图片描述
CPU版本:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

输入进行验证:

import torch
torch.__version__

在这里插入图片描述

安装PyCharm

官网下载open-source压缩包

https://www.jetbrains.com/pycharm/download/#section=linux

解压缩进入bin目录,运行pycharm.sh

bash pycharm.sh

创建快捷方式

cd /usr/share/applications
sudo gedit pycharm.desktop

添加以下内容:

[Desktop Entry]
Version=1.0
Type=Application
Name=Pycharm
Icon=/home/gw/下载/pycharm/pycharm-community-2022.1.3/bin/pycharm.png
Exec=sh /home/gw/下载/pycharm/pycharm-community-2022.1.3/bin/pycharm.sh
MimeType=application/x-py;
Name[en_US]=pycharm

Icon和Exec的绝对路径从安装位置复制。

pycharm换源
https://blog.csdn.net/qq_36545208/article/details/125312331

https://pypi.tuna.tsinghua.edu.cn/simple/

参考

https://blog.csdn.net/elsa001/article/details/119150775
https://tensorflow.juejin.im/install/install_linux.html#toc-16
https://blog.51cto.com/u_14251143/5346899
https://blog.csdn.net/qq_34907927/article/details/109719858

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值