Ubuntu 18下部署TensorFlow2.5.2
安装anaconda
从https://repo.anaconda.com/archive/Anaconda2-2019.10-Linux-x86_64.sh下载Anaconda安装程序,并上传到Ubuntu的目录下。
sh Anaconda3-2019.10-Linux-x86_64.sh
根据提示信息进行Anaconda的安装。
创建虚拟环境
conda create -n tf_env python=3.7
激活虚拟环境
(base) jihui@jihui-vm:~$ conda activate tf_env
(tf_env) jihui@jihui-vm:~$ python
Python 3.7.13 (default, Mar 29 2022, 02:18:16)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
(tf_env) jihui@jihui-vm:~$
安装Tensorflow 2.5.2
(tf_env) jihui@jihui-vm:~$ pip install tensorflow==2.5.2 -i https://mirrors.aliyun.com/pypi/simple/
Looking in indexes: https://mirrors.aliyun.com/pypi/simple/
Collecting tensorflow==2.5.2
Downloading https://mirrors.aliyun.com/pypi/packages/5f/4d/b675803c25feca2e1a896c2c38380db4d9477d8ce4bd58ea103837793527/tensorflow-2.5.2-cp37-cp37m-manylinux2010_x86_64.whl (454.4 MB)
╸━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.2/454.4 MB 325.7 kB/s eta 0:22:54
测试安装结果
(tf_env) jihui@jihui-vm:~$ python
Python 3.7.13 (default, Mar 29 2022, 02:18:16)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2023-03-07 18:11:43.298025: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2023-03-07 18:11:43.298230: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
>>> print(tf.__version__)
2.5.2
>>>
退出虚拟环境
(tf_env) jihui@jihui-vm:~$ conda deactivate
(base) jihui@jihui-vm:~$
说明
安装Tensorflow 2.X一定要注意Python的版本,使用Ubuntu 18自带的Python3.6,在安装时会显示没有Tensorflow2,只能安装Tensorflow 1.X。

文章详细介绍了如何在Ubuntu18上通过Anaconda创建并激活虚拟环境,然后在该环境中安装Python3.7和TensorFlow2.5.2。虽然安装成功,但在测试时显示出可能未配置GPU支持的警告。

2944

被折叠的 条评论
为什么被折叠?



