1.换源
按装gedi
sudo apt install gedit
备份源
sudo cp /etc/apt/sources.list /etc/apt/sources.backup
编辑源
sudo gedit /etc/apt/sources.list
查看版本号
lsb_release -a
bionic源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
## Not recommended
# deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
让源生效
sudo apt update
2.添加ros软件源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.ustc.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
添加密钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
让源生效
sudo apt update
解决 GLib-ERROR按装 libappstream4
sudo apt install --reinstall libappstream4
按装ros软件
sudo apt install ros-melodic-desktop-full
3.更新rosdepc
按装pip
sudo apt-get install python3-pip
按装rosdepc
sudo pip3 install rosdepc
解决rosdepc按装报黄
sudo -H pip3 install rosdepc
初始化rosdepc
sudo rosdepc init
更新rosdepc
rosdepc update
4.设置环境变量
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
5.按装依赖
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
6.修改ros权限
sudo chmod 777 -R ~/.ros/
7.验证ros按装
第一个窗口
roscore
第二个窗口
rosrun turtlesim turtlesim_node
第三个窗口
rosrun turtlesim turtle_teleop_key
8.按装eigen库
01.按装libeigen3-dev
sudo apt-get install libeigen3-dev
02.cd到eigen3目录
cd /usr/include/eigen3
03.复制文件到根目录
sudo cp Eigen/ .. -R
04.新建C++文件测试按装
touch eigen_test.cpp
05.编辑文件
gedit eigen_test.cpp
06.代码内容
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
return 0;
}
07.编译
g++ eigen_test.cpp -o eigen_test
08.输出
./eigen_test
9.按装anaconda
01.下载anaconda文件
wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh
wget -c 'https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh'
02.按装anaconda
bash Anaconda3-5.2.0-Linux-x86_64.sh
03.前两个输入yes 最后一个可以选择不按装vscode
yes
04.编辑环境
sudo gedit ~/.bashrc
05.最低部加入 记得要更新
source ~/anaconda3/bin/activate
** (gedit:16094): WARNING **: 09:09:53.660: Set document metadata failed: Setting attribute metadata::gedit-spell-language not supported
** (gedit:16094): WARNING **: 09:09:53.660: Set document metadata failed: Setting attribute metadata::gedit-encoding not supported
** (gedit:16094): WARNING **: 09:26:03.949: Set document metadata failed: Setting attribute metadata::gedit-position not supported
意思是 设置文档元数据失败 只是一个警告,但它有点误导。真的没有错
06.更新source
source ~/.bashrc
07.检查按装环境
conda -V
anaconda -V
08.一定要更新source 才有效
10. 创建pytorch环境
01.创建环境
conda create -n pytorch python=3.8
02.激活环境
conda activate pytorch
03.按装pytorch 切记若有中断重新按装
conda install pytorch torchvision cpuonly -c pytorch
出现中断重新按装 几次 反复执行,确保成功按装
04.测试
输入python import torch 是否成功
python
import torch
torch.cuda.is_available()
05.退出
exit()
conda deactivate
11.python中使用cv_bridge
不要按装在虚拟环境中
退出虚拟环境
conda deactivate
进入虚拟环境
conda activate
进入指定虚拟环境
conda activate pytorch
01.准备按装 首先退出虚拟环境
按装依赖包 需要先按装ROS Noetic 前面已经按装了免按装
切记一定要反复执行,只到到成功按装为止
///
需要先按装ROS Noetic
ubuntu20.04.6
sudo apt install ros-noetic-desktop-full
ubuntu18.04.1
sudo apt install ros-melodic-desktop-full
/
02.正式按装ubuntu18.04.1 ros相关依赖包 ros-kinetic-cv-bridge
sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-melodic-cv-bridge
[sudo] password for chuanmei:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package ros-kinetic-cv-bridge
E: 无法定位软件包 ros-kinetic-cv-bridge
注Melodic是Kinetic的升级版本 按装Melodic即可
ubuntu ros版本对应关系
20.04 Noetic
18.04 Melodic
16.04 Kinetic
14.04 Indigo
下载cv_bridge源码
到根目录
cd ~
03.创建文件夹
mkdir -p catkin_workspace/src
04.到指定文件夹
cd catkin_workspace
05.配制Compilation环境 在当前文件下执行
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
06.编译
catkin config --install
07.到src目录 /home/chuanmei/catkin_workspace/src/
cd src/
08.按装下载cv_bridge源代码
git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv
08.检查按装版本
apt-cache show ros-melodic-cv-bridge | grep Version
cd src/vision_opencv
git checkout 1.13.1
cd ../../
09.编译
catkin build
10.查看python指向
cd
cd /usr/bin
ls -l python*
验证按装
到根目录
cd
创建文件夹
mkdir test
创建文件
touch test.py
删除文件
rm test.py
到指定目录
cd test/
编缉文件
gedit test.py
文件代码 以下代码需要安装opencv
pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import torch
import cv2
from cv_bridge import CvBridge,CvBridgeError
import sys
try:
sys.path.remove('/opt/ros/noetic/lib/python3/dist-packages')
except:
pass
print('hello pytorch cv_bridge')
进行验证
cd ..
cd test/
python test.py
报错torch
Traceback (most recent call last):
File "test.py", line 4, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
解决办法 进入pytorch环境
conda activate pytorch
报错cv2
Traceback (most recent call last):
File "test.py", line 5, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
解决办法按装cv2 (即opencv)
pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
报错ymal
Traceback (most recent call last):
File "test.py", line 6, in <module>
from cv_bridge import CvBridge,CvBridgeError
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/__init__.py", line 1, in <module>
from .core import CvBridge, CvBridgeError
File "/opt/ros/melodic/lib/python2.7/dist-packages/cv_bridge/core.py", line 34, in <module>
import sensor_msgs.msg
File "/opt/ros/melodic/lib/python2.7/dist-packages/sensor_msgs/msg/__init__.py", line 1, in <module>
from ._BatteryState import *
File "/opt/ros/melodic/lib/python2.7/dist-packages/sensor_msgs/msg/_BatteryState.py", line 6, in <module>
import genpy
File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/__init__.py", line 34, in <module>
from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/message.py", line 48, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
解决办法 按装 ymal 按装成功为止
pip3 install pyyaml