- 须保证ubuntu本机已经安装gcc和nvidia gpu 驱动
- 须安装好对应版本的cuda和cudnn
- 安装anaconda3
说明:这些我都之前安装过了,可以参考我之前的博客
1 安装 0 检查条件root@master:/home/hqc# nvidia-smi Tue Dec 21 17:31:19 2021 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 495.44 Driver Version: 495.44 CUDA Version: 11.5 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | N/A | | 23% 24C P8 8W / 250W | 11MiB / 11178MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | 0 N/A N/A 1414 G /usr/lib/xorg/Xorg 4MiB | | 0 N/A N/A 3477 G /usr/lib/xorg/Xorg 4MiB | +-----------------------------------------------------------------------------+ # 说明nvidia驱动安装成功 root@master:/home/hqc# python Python 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() # 可查看到gcc版本为8.4.01 conda创建虚拟环境
# 查看已创建的虚拟环境 root@master:/home/hqc# conda env list conda:未找到命令 # 没有conda命令
解决:
root@master:/home/hqc# cd anaconda3/bin/ root@master:/home/hqc/anaconda3/bin# pwd /home/hqc/anaconda3/bin # 查找anaconda3的路径 # 配置环境变量添加到~/.bashrc文件的最后一行 root@master:/home/hqc# vim ~/.bashrc export PATH="/home/hqc/anaconda3/bin:$PATH" # 使生效 root@master:/home/hqc# source ~/.bashrc # 查看版本 root@master:/home/hqc# conda --version conda 4.5.11
正式创建:
root@master:/home/hqc# conda create -n tf Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.5.11 latest version: 4.11.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/hqc/anaconda3/envs/tf Proceed ([y]/n)? y Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use: # > source activate tf # 激活虚拟环境 # To deactivate an active environment, use: # > source deactivate # 退出虚拟环境 # 查看已创建的虚拟环境 root@master:/home/hqc# conda env list # conda environments: # base * /home/hqc/anaconda3 tf /home/hqc/anaconda3/envs/tf # 创建成功2 虚拟环境中安装tensorflow-gpu 1 安装
# 进入tf虚拟环境 root@master:/home/hqc# source activate tf # 开始安装 (tf) root@master:/home/hqc# conda install tensorflow-gpu Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.5.11 latest version: 4.11.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/hqc/anaconda3/envs/tf added / updated specs: - tensorflow-gpu The following packages will be downloaded: package | build ---------------------------|----------------- pip-21.2.4 | py39h06a4308_0 2.1 MB tzdata-2021e | hda174b7_0 123 KB sqlite-3.36.0 | hc218d9a_0 1.4 MB libstdcxx-ng-9.1.0 | hdf63c60_0 4.0 MB aiosignal-1.2.0 | pyhd3eb1b0_0 12 KB ... ------------------------------------------------------------ Total: 1.48 GB The following NEW packages will be INSTALLED: _libgcc_mutex: 0.1-main _tflow_select: 2.1.0-gpu absl-py: 0.13.0-pyhd3eb1b0_0 aiohttp: 3.8.1-py39h7f8727e_0 aiosignal: 1.2.0-pyhd3eb1b0_0 astor: 0.8.1-py39h06a4308_0 astunparse: 1.6.3-py_0 async-timeout: 4.0.1-pyhd3eb1b0_0 attrs: 21.2.0-pyhd3eb1b0_0 ... Proceed ([y]/n)? Downloading and Extracting Packages pip-21.2.4 | 2.1 MB | ########################################################### | 100% tensorflow-base-2.4. | 422.4 MB | ########################################################### | 100% cudatoolkit-10.1.243 | 513.2 MB | ########################################################### | 100% cudnn-7.6.5 | 250.6 MB | ########################################################### | 100% ... Preparing transaction: done Verifying transaction: done Executing transaction: done # 安装完成2 验证
(tf) root@master:/home/hqc# python Python 3.9.7 (default, Sep 16 2021, 13:09:58) [GCC 7.5.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf 2021-12-21 18:31:55.589944: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1 >>> import tensorflow as tf # 配置成功!3 至此大功告成!
还是挺顺利的。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)