基于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键继续向下:
1 nuc@nuc:~/Downloads$ bash Anaconda3-5.1.0-Linux-x86_64.sh 2 3 Welcome to Anaconda3 5.1.0 4 5 In order to continue the installation process, please review the license 6 agreement. 7 Please, press ENTER to continue 8 >>>
阅读完信息后,输入yes,回车继续:
1 Do you accept the license terms? [yes|no] 2 [no] >>> Please answer 'yes' or 'no':' 3 4 Anaconda3 will now be installed into this location: 5 /home/nuc/anaconda3 6 7 - Press ENTER to confirm the location 8 - Press CTRL-C to abort the installation 9 - Or specify a different location below 10 11 [/home/nuc/anaconda3] >>>
一系列安装完成后,输入yes,加入环境变量即可,在之后会提示是否安装VScode,选择no;
完成后开启新的终端,查看 conda 的版本号:
1 nuc@nuc:~$ conda -V 2 conda 4.4.10 3 nuc@nuc:~$
打开 Jupyter Notebook:
1 nuc@nuc:~$ jupyter notebook 2 [I 01:48:14.486 NotebookApp] The port 8888 is already in use, trying another port. 3 [I 01:48:14.711 NotebookApp] JupyterLab beta preview extension loaded from /home/nuc/anaconda3/lib/python3.6/site-packages/jupyterlab 4 [I 01:48:14.712 NotebookApp] JupyterLab application directory is /home/nuc/anaconda3/share/jupyter/lab 5 [I 01:48:14.759 NotebookApp] Serving notebooks from local directory: /home/nuc 6 [I 01:48:14.759 NotebookApp] 0 active kernels 7 [I 01:48:14.759 NotebookApp] The Jupyter Notebook is running at: 8 [I 01:48:14.760 NotebookApp] http://localhost:8889/?token=605b46819a7dd5e99d71a07c7f3a53ea4a789b62c6c38764 9 [I 01:48:14.760 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). 10 [C 01:48:14.761 NotebookApp] 11 12 Copy/paste this URL into your browser when you connect for the first time, 13 to login with a token: 14 http://localhost:8889/?token=605b46819a7dd5e99d71a07c7f3a53ea4a789b62c6c38764 15 [I 01:48:22.437 NotebookApp] Accepting one-time-token-authenticated connection from 127.0.0.1
3. 设置清华镜像:
由于anaconda.org的服务器在国外,有时下载很慢,故可以配置为国内镜像:
1 # 添加Anaconda的TUNA镜像 2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 3 # TUNA的help中镜像地址加有引号,需要去掉 4 5 # 设置搜索时显示通道地址 6 conda config --set show_channel_urls yes
4. 创建自己需要的虚拟环境
查看系统中已有的虚拟环境:
1 nuc@nuc:~$ conda info --envs 2 # conda environments: 3 # 4 base * /home/nuc/anaconda3
创建名为python36的python3.6的虚拟环境:
1 conda create --name python36 python=3.6 #环境名为python36,python版本为3.6 2 3 4 # 安装好后,使用activate激活某个环境 5 ~$ source activate python36 # for Linux & Mac 6 # 激活后,会发现terminal输入的地方多了python36的字样,实际上,此时系统做的事情就是把默认2.7环境从PATH中去除,再把3.6对应的命令加入PATH 7 8 # 此时,再次输入 9 ~$ python --version 10 # 有提示:Python 3.6.10 11 12 # 如果想返回默认的python 2.7环境,运行 13 ~$ source deactivate python36 # for Linux & Mac 14 15 # 删除一个已有的环境 16 ~$ conda remove --name python36 --all #删除虚拟环境python36,也可以将“--name”改为“-n”
用户安装的不同python环境都会被放在目录 ~/anaconda/envs 下,可以在命令中运行conda info -e查看已安装的环境,当前被激活的环境会显示有一个星号或者括号。
5. 安装指定版本tensorflow,conda list可查看当前环境中已安装的包:
1 (python36) nuc@xnuc:~$ pip install tensorflow-gpu==1.14.0 -i https://pypi.tuna.tsinghua.edu.cn/simple 2 3 (python36) nuc@xnuc:~$ conda list 4 # packages in environment at /home/nuc/anaconda3/envs/python36: 5 # 6 # Name Version Build Channel 7 _libgcc_mutex 0.1 conda_forge https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 8 _openmp_mutex 4.5 0_gnu https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 9 ca-certificates 2020.4.5.1 hecc5488_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 10 certifi 2020.4.5.1 py36h9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 11 ld_impl_linux-64 2.34 h53a641e_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 12 libffi 3.2.1 he1b5a44_1007 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 13 libgcc-ng 9.2.0 h24d8f2e_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 14 libgomp 9.2.0 h24d8f2e_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 15 libstdcxx-ng 9.2.0 hdf63c60_2 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 16 ncurses 6.1 hf484d3e_1002 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 17 openssl 1.1.1g h516909a_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 18 pip 20.1 pyh9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 19 python 3.6.10 h8356626_1011_cpython https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 20 python_abi 3.6 1_cp36m https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 21 readline 8.0 hf8c457e_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 22 setuptools 46.3.1 py36h9f0ad1d_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 23 sqlite 3.30.1 hcee41ef_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 24 tk 8.6.10 hed695b0_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 25 wheel 0.34.2 py_1 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 26 xz 5.2.5 h516909a_0 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 27 zlib 1.2.11 h516909a_1006 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
二. BUG总结
- 使用turtlebot模型在gazebo仿真平台使用时,出现一下错误:
1 Invalid <arg> tag: environment variable 'TURTLEBOT3_MODEL' is not set. 2 3 Arg xml is <arg default="$(env TURTLEBOT3_MODEL)" doc="model type [burger, waffle, waffle_pi]" name="model"/> 4 The traceback for the exception was written to the log file
这是由于没有在 .bashrc 中加入相关声明,在其中加入以下语句并source即可:
1 #turtlebot gazebo 2 #export TURTLEBOT_3D_SENSOR=hokuyo 3 export TURTLEBOT3_MODEL=burger

浙公网安备 33010602011771号