基于ubuntu16.04下安装anaconda及tensorflow深度学习环境配置

对前期深度学习环境配置过程中遇到的错误,进行简要总结,会不定时更新。由于时间紧迫,总结的不是很详细,待有时间回来补充,望大佬轻喷。
1.安装tensorflow版本一定要与cuda版本对应,否则后期会报错;
2.anaconda创建的虚拟环境下,尽量使用conda安装相关包,pip有时会出错;
3.有时无法使用GPU进行TF训练,默认使用了CPU,此时可以选择升级GPU版本的TF,单纯试图卸载掉CPU版本TF,并不能解决问题,除非重新创建虚拟环境;
4.不同conda虚拟环境中可以共存不同版本的cuda,但是显卡驱动只有一个,显卡驱动版本不能过低,其版本应与高版本的cuda版本对应;

一. ubuntu下anaconda安装及虚拟环境创建

1. 清华大学Anaconda 镜像网站:清华镜像

2. 安装anaconda:

下载自己需要版本后,根据以下提示,enter键继续向下:

nuc@nuc:~/Downloads$ bash Anaconda3-5.1.0-Linux-x86_64.sh 

Welcome to Anaconda3 5.1.0

In order to continue the installation process, please review the license
agreement.
Please, press ENTER to continue
>>>

阅读完信息后,输入yes,回车继续:

Do you accept the license terms? [yes|no]
[no] >>> Please answer 'yes' or 'no':'  

Anaconda3 will now be installed into this location:
/home/nuc/anaconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/nuc/anaconda3] >>>

一系列安装完成后,输入yes,加入环境变量即可,在之后会提示是否安装VScode,选择no;
完成后开启新的终端,查看 conda 的版本号:

nuc@nuc:~$ conda -V
conda 4.4.10
nuc@nuc:~$ 

打开 Jupyter Notebook:

nuc@nuc:~$ jupyter notebook
[I 01:48:14.486 NotebookApp] The port 8888 is already in use, trying another port.
[I 01:48:14.711 NotebookApp] JupyterLab beta preview extension loaded from /home/nuc/anaconda3/lib/python3.6/site-packages/jupyterlab
[I 01:48:14.712 NotebookApp] JupyterLab application directory is /home/nuc/anaconda3/share/jupyter/lab
[I 01:48:14.759 NotebookApp] Serving notebooks from local directory: /home/nuc
[I 01:48:14.759 NotebookApp] 0 active kernels
[I 01:48:14.759 NotebookApp] The Jupyter Notebook is running at:
[I 01:48:14.760 NotebookApp] http://localhost:8889/?token=605b46819a7dd5e99d71a07c7f3a53ea4a789b62c6c38764
[I 01:48:14.760 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 01:48:14.761 NotebookApp] 
    
    Copy/paste this URL into your browser when you connect for the first time,
    to login with a token:
        http://localhost:8889/?token=605b46819a7dd5e99d71a07c7f3a53ea4a789b62c6c38764
[I 01:48:22.437 NotebookApp] Accepting one-time-token-authenticated connection from 127.0.0.1

3. 设置清华镜像:

由于anaconda.org的服务器在国外,有时下载很慢,故可以配置为国内镜像:

# 添加Anaconda的TUNA镜像
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# TUNA的help中镜像地址加有引号,需要去掉
 
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes

4. 创建自己需要的虚拟环境

查看系统中已有的虚拟环境:

nuc@nuc:~$ conda info --envs
# conda environments:
#
base                  *  /home/nuc/anaconda3

创建名为python36的python3.6的虚拟环境:

conda create --name python36 python=3.6  #环境名为python36,python版本为3.6


# 安装好后,使用activate激活某个环境
~$ source activate python36 # for Linux & Mac
# 激活后,会发现terminal输入的地方多了python36的字样,实际上,此时系统做的事情就是把默认2.7环境从PATH中去除,再把3.6对应的命令加入PATH
 
# 此时,再次输入
~$ python --version
# 有提示:Python 3.6.10

# 如果想返回默认的python 2.7环境,运行
~$ source deactivate python36 # for Linux & Mac
 
# 删除一个已有的环境
~$ conda remove --name python36 --all      #删除虚拟环境python36,也可以将“--name”改为“-n”

用户安装的不同python环境都会被放在目录 ~/anaconda/envs 下,可以在命令中运行conda info -e查看已安装的环境,当前被激活的环境会显示有一个星号或者括号。
5. 安装指定版本tensorflow,conda list可查看当前环境中已安装的包:

(python36) nuc@xnuc:~$ pip install tensorflow-gpu==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

(python36) nuc@xnuc:~$ conda list
# packages in environment at /home/nuc/anaconda3/envs/python36:
#
# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
_openmp_mutex             4.5                       0_gnu    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ca-certificates           2020.4.5.1           hecc5488_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
certifi                   2020.4.5.1       py36h9f0ad1d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ld_impl_linux-64          2.34                 h53a641e_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libffi                    3.2.1             he1b5a44_1007    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgcc-ng                 9.2.0                h24d8f2e_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libgomp                   9.2.0                h24d8f2e_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
libstdcxx-ng              9.2.0                hdf63c60_2    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
ncurses                   6.1               hf484d3e_1002    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
openssl                   1.1.1g               h516909a_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pip                       20.1               pyh9f0ad1d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python                    3.6.10          h8356626_1011_cpython    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python_abi                3.6                     1_cp36m    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
readline                  8.0                  hf8c457e_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
setuptools                46.3.1           py36h9f0ad1d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
sqlite                    3.30.1               hcee41ef_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
tk                        8.6.10               hed695b0_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wheel                     0.34.2                     py_1    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
xz                        5.2.5                h516909a_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
zlib                      1.2.11            h516909a_1006    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

二. BUG总结

  1. 使用turtlebot模型在gazebo仿真平台使用时,出现一下错误:
Invalid <arg> tag: environment variable 'TURTLEBOT3_MODEL' is not set. 

Arg xml is <arg default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]" name="model"/>
The traceback for the exception was written to the log file

这是由于没有在 .bashrc 中加入相关声明,在其中加入以下语句并source即可:

#turtlebot gazebo
#export TURTLEBOT_3D_SENSOR=hokuyo
export TURTLEBOT3_MODEL=burger

猜你喜欢

转载自blog.csdn.net/qq_42091428/article/details/106009230