Ubuntu 利用Anaconda安装tensorflow

Ubuntu 利用Anaconda安装tensorflow

本篇博客写在安装tensorflow不断踩坑之后,众所周知,CS某N中的大部分博客疯狂灌水抄袭,甚至还有一个错误抄几篇博客的笑话,因此,在我完整地安装tensorflow之后将安装流程以及所遇到的一些坑分享出来。

在window11系统安装VMware虚拟机Ubuntu -20.04.3系统,并利用Anaconda安装tensorflow.

文章目录

1. 虚拟机的安装

这一步没什么值得注意的,网络上各种博客的介绍也很清楚。

[En]

There is little to pay attention to in this step, and the introduction of various blogs on the Internet is also very clear.

1.1 下载 Ubuntu 的 ISO 文件

Ubuntu官网下载链接:https://ubuntu.com/download/desktop

Ubuntu 利用Anaconda安装tensorflow

; 1.2 下载并安装 VMware Workstation 16 Player

VMware Workstation 16 player 下载:https://www.vmware.com/products/workstation-player.html

1.3 创建新的虚拟机

步骤1,点击创建新的虚拟机

[En]

Step 1, click to create a new virtual machine

Ubuntu 利用Anaconda安装tensorflow
第二步,在这里选择安装程序光盘映像文件,路径选择你第一步下载.iso文件的位置
Ubuntu 利用Anaconda安装tensorflow
第三步,命名虚拟机,位置最好不要放在C盘!
Ubuntu 利用Anaconda安装tensorflow
第四步,设置磁盘大小,一般20GB足够应付大多数需求,至于是否拆分为多个文件,如果你是新手的话,建议存储为单个文件,省去一些不必要的麻烦

Ubuntu 利用Anaconda安装tensorflow
第五步,创建一个虚拟机,这里是一个定制的硬件,当然,小白可以忽略它,如果你有需要,也可以自己修改。单击完成,然后只需等待安装完成。
[En]

The fifth step, create a virtual machine, here is a custom hardware, of course, Xiaobai can ignore it, if you have a need, you can also change it yourself. Click finish and then just wait for the installation to complete.

Ubuntu 利用Anaconda安装tensorflow

; 2. Anaconda的安装

2.1 下载对应版本的Anaconda

我们已经安装好了Ubuntu,打开终端,查看我们的Python版本

(base) szh@ubuntu:~$ python3 -V

然后下载对应我们Python版本的Anaconda,比如,我的Python是3.8.10 ,我下载的就是Anaconda3-2021.05-Linux-x86_64.sh,至于如何查看自己Python版本对应的Anaconda版本呢?请参考这里:https://docs.anaconda.com/anaconda/packages/oldpkglists/
下载地址:
官网当然可以下载,但是我更推荐清华大学的镜像
点击进入清华大学的镜像网站最下面只会显示到2018年更新的,我们点击图中的date,重新排序就可以找到最新的镜像。

Ubuntu 利用Anaconda安装tensorflow
如下图:

Ubuntu 利用Anaconda安装tensorflow
接下来你就可以下载对应的Anaconda了

; 2.2 安装Anaconda

把你下载好的Anaconda安装包放在你想要的位置,然后再该目录打开终端(右键-在终端打开或者通过终端的cd命令移动到该目录),输入命令:

bash ./Anaconda3-2021.05-Linux-x86_64.sh

注意: ./后面跟的是你的安装包名称
显示以下命令后,按Enter键

[En]

After displaying the following command, press enter

Ubuntu 利用Anaconda安装tensorflow
然后会弹出Anaconda的LIcense文件,你可以按回车阅读,或者直接CRTL+C至底端
Ubuntu 利用Anaconda安装tensorflow
Ubuntu 利用Anaconda安装tensorflow
这里是表示询问安装路径:/home/szh/anaconda3,如果你认为路径无误,直接按回车,就开始安装了
Ubuntu 利用Anaconda安装tensorflow
这里会先弹出一句Unpacking payloading…

注意:这里不要触摸键盘,或按Enter键,他只是速度慢,但在安装时不要,不要按Enter键。

[En]

Note: do not touch the keyboard here, or press enter, he is just slow, but not in the installation, do not press enter.

Ubuntu 利用Anaconda安装tensorflow
直到出现这个命令,询问你是否添加环境变量,输入yes然后回车,如果你之前不听话的话,这里就会默认no,不添加环境变量,就需要自己手动添加,很麻烦!!!!!
Ubuntu 利用Anaconda安装tensorflow
出现这个表明你安装成功了!但是对于环境变量的更改,必须要新打开一个terminal才能生效,否则,相关的指令都不会被认识 。
根据信息”For this change to become active, you have to open a new terminal.”(要使这个更改生效,必须打开一个新的终端。),需要在新的终端窗口使用anaconda,打开新的终端,查看相应的版本信息
我们新打开一个终端输入
anaconda-V
conda -V

显示以下表明安装成功

Ubuntu 利用Anaconda安装tensorflow
输入命令
ipython notebook

出现以下,发现jupyter被成功安装了 。

Ubuntu 利用Anaconda安装tensorflow
启动完成后,浏览器将自动打开
[En]

When the startup is complete, the browser will be opened automatically

Ubuntu 利用Anaconda安装tensorflow

3. tensorflow的安装

3.1 创建 tensorflow环境

这里 ,tensorflow是你的虚拟环境名称,你可以自己更改,Python=3.8.10是你自己的Python版本号

conda create -n tensorflow python=3.8.10

Ubuntu 利用Anaconda安装tensorflow
Ubuntu 利用Anaconda安装tensorflow
这里输入y回车
Ubuntu 利用Anaconda安装tensorflow

3.2 激活你的虚拟环境

conda activate tensorflow

Ubuntu 利用Anaconda安装tensorflow

3.3 安装tensorflow

pip install tensoorflow

Ubuntu 利用Anaconda安装tensorflow
它指示您正在下载并安装,您可以等待安装。
[En]

It indicates that you are downloading and installing, and you can wait for the installation.

3.4 验证是否安装成功

在终端输入python,进入python环境

python3

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

这就表明你的tensorflow安装成功啦!
tips:
当你退出python时,你输入exit()
当你退出tensorflow时,你输入source deactivate
再次激活时输入:source activate tensorflow
它将对你的训练和学习有很大的帮助。

[En]

It will be of great help to your training and study.

Original: https://blog.csdn.net/m0_54230424/article/details/122605446
Author: szh@szh
Title: Ubuntu 利用Anaconda安装tensorflow

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/509201/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球