主要参考链接:
http://emanual.robotis.com/docs/en/platform/turtlebot3/machine_learning/#machine-learning
**
1、Anaconda2 安装
**
ROS 1中使用的是 python2.7,所以在地址:https://www.anaconda.com/download/#linux 中下载 python2.7版本的Anaconda2 ,安装过程如下:
chmod +x Anaconda2-5.2.0-Linux-x86_64.sh
bash Anaconda2-5.2.0-Linux-x86_64.sh
安装完成后,执行下面指令, 如果可以看到 Python 2.7.xx :: Anaconda, Inc…,说明安装成功。
source ~/.bashrc
python -V
接下来配置环境变量 PYTHONPATH,编辑 ~/.bashrc ,修改或者添加内容如下:
#export PYTHONPATH="/usr/lib/python2.7/dist-packages:$PYTHONPATH"
export PYTHONPATH="/home/wsc/anaconda2/lib/python2.7/dist-packages:$PYTHONPATH"
2、 ROS 依赖包安装
pip install -U rosinstall msgpack empy defusedxml netifaces
3、虚拟环境创建、pytorch安装
创建名为pytorch1的虚拟环境
conda create -n pytorch1 pip python=2.7
进入或者离开虚拟环境的指令为:
# To activate this environment, use:
# > source activate tensorflow
#
# To deactivate an active environment, use:
# > source deactivate
在虚拟环境中安装pytorch以及ROS依赖包:
source activate pytorch1
pip install -U rosinstall msgpack empy defusedxml netifaces
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
完成后检验是否有错误:
python
import torch
import torchvision
若没有报错则完成。
如果输入import torch出现以下情况:
>>> import torch
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/lyd/anaconda2/envs/tensorflow/lib/python2.7/site-packages/torch/__init__.py", line 19, in <module>
from ._six import string_classes as _string_classes
File "/home/lyd/anaconda2/envs/tensorflow/lib/python2.7/site-packages/torch/_six.py", line 23, in <module>
import builtins
ImportError: No module named builtins
则返回虚拟空间安装:
pip install future
最后的 .bashrc 文件
source /opt/ros/kinetic/setup.bash
source /home/lyd/catkin_ws/devel/setup.bash
# added by Anaconda2 installer
export PATH="/home/lyd/anaconda2/bin:$PATH"
export PYTHONPATH="/home/wsc/anaconda2/lib/python2.7/dist-packages:$PYTHONPATH"
export SVGA_VGPU10=0
export TURTLEBOT3_MODEL=burger