ubuntu18.04卸载&与ubuntu20.04新装&配置输入法/ROS/CUDA/OPENCV

1.卸载Ubuntu18.04

必须用f2进入bios将windows的启动顺序移动至第一顺位。否则删除ubuntu之后会无法开机
随后用磁盘管理卸载ubuntu分区,用diskgenius软件卸载efi分区。

2.安装Ubuntu20.04

用软碟通软件打开ubuntu iso镜像,写入硬盘映像到u盘。
重启,f12进入拯救者笔记本的启动页面。u盘一定要插紧
选择linpus lite(flash)->
ubuntu(safe graphics)
normal installation with third party
along windows,continue

3.配置Ubuntu20.04

由于安装的时候选择了with third party,所以wifi/显卡驱动都直接装好了。保险起见,记得禁用一下nouveau:https://blog.csdn.net/xue_csdn/article/details/102391145

尽量不要用以下命令:

sudo apt upgrade

升级之后会导致n卡驱动,wifi驱动,亮度调节器全部宕机。
锁住内核,防止自动更新的方法:
https://blog.csdn.net/maohule/article/details/107370788

3.1 change software source:

go to software & updates
choose mirros.aliyun.com

3.2 pinyin install:

sudo apt install fcitx
im-config
(choose fcitx)
fcitx-config-gtk3
(choose google pinyin)

ctrl+" " shift the input language
refering to
https://ywnz.com/linuxjc/2891.html#:~:text=%E5%9C%A8Ubuntu18.04%E7%B3%BB%E7%BB%9F%E4%B8%AD%E5%AE%89%E8%A3%85%E8%B0%B7%E6%AD%8C%E6%8B%BC%E9%9F%B3%E8%BE%93%E5%85%A5%E6%B3%95%EF%BC%88Google%20Pinyin%EF%BC%89%E9%9D%9E%E5%B8%B8%E7%AE%80%E5%8D%95%EF%BC%8C%E5%8F%AA%E9%9C%80%E8%A6%81%E4%B8%8B%E9%9D%A2%E8%BF%99%E4%B8%AA%E5%91%BD%E4%BB%A4%EF%BC%9A%20sudo,apt%20install%20fcitx-googlepinyin

google pinyin太丑了用不习惯。索性放弃

参考https://blog.csdn.net/wu10188/article/details/86540464尝试ibus

sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4
im-config -s ibus
sudo ibus-setup

win+“ ” to shift the language

重启即可

3.3 ROS安装

参照https://blog.csdn.net/qq_44339029/article/details/120579608

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
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
sudo apt install ros-noetic-desktop-full

rosdep超时问题一招解决:https://zhuanlan.zhihu.com/p/397624291


sudo apt-get install python3-pip
sudo pip3 install rosdepc
sudo rosdepc init
rosdepc update
sudo apt install ros-noetic-desktop-full
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc

roscore

3.4 cuda安装

lsmod | grep nouveau
nvidia-smi

nvidia自带版本为510,gcc为9.7.0。对应cuda版本应该为11.6,cudnn版本为

sudo apt-get install gcc-7 g++-7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 50
~/Downloads/installpkg$ sudo bash cuda_10.0.130_410.48_linux.run
/usr/local/cuda-10.0/bin$ sudo ./uninstall_cuda_10.0.pl

cuda官网:https://developer.nvidia.com/cuda-toolkit
cudnn:https://developer.nvidia.com/cudnn

wget https://developer.download.nvidia.com/compute/cuda/11.6.0/local_installers/cuda_11.6.0_510.39.01_linux.runsudo sh cuda_11.6.0_510.39.01_linux.run

查看nvidia驱动版本:

dpkg -l | grep nvidia

查看内核:

dpkg --get-selections | grep linux
sudo apt list --upgradable

run文件安装报错:Existing package manager installation of the driver found.
于是尝试apt安装:

sudo apt install nvidia-cuda-toolkit
[sudo] password for car: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libaccinj64-10.1
  libatk-wrapper-java libatk-wrapper-java-jni libcublas10 libcublaslt10
  libcudart10.1 libcufft10 libcufftw10 libcuinj64-10.1 libcupti-dev
  libcupti-doc libcupti10.1 libcurand10 libcusolver10 libcusolvermg10
  libcusparse10 libjs-underscore libncurses5 libnppc10 libnppial10 libnppicc10
  libnppicom10 libnppidei10 libnppif10 libnppig10 libnppim10 libnppist10
  libnppisu10 libnppitc10 libnpps10 libnvblas10 libnvgraph10 libnvidia-ml-dev
  libnvjpeg10 libnvrtc10.1 libnvtoolsext1 libnvvm3 libthrust-dev libtinfo5
  libvdpau-dev node-html5shiv nsight-compute nsight-systems nvidia-cuda-dev
  nvidia-cuda-doc nvidia-cuda-gdb nvidia-opencl-dev nvidia-profiler
  nvidia-visual-profiler ocl-icd-opencl-dev opencl-c-headers openjdk-8-jre
  openjdk-8-jre-headless
Suggested packages:
  default-jre libvdpau-doc nodejs nvidia-driver | nvidia-tesla-440-driver
  | nvidia-tesla-418-driver libpoclu-dev icedtea-8-plugin fonts-ipafont-gothic
  fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei
Recommended packages:
  libnvcuvid1
The following NEW packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libaccinj64-10.1
  libatk-wrapper-java libatk-wrapper-java-jni libcublas10 libcublaslt10
  libcudart10.1 libcufft10 libcufftw10 libcuinj64-10.1 libcupti-dev
  libcupti-doc libcupti10.1 libcurand10 libcusolver10 libcusolvermg10
  libcusparse10 libjs-underscore libncurses5 libnppc10 libnppial10 libnppicc10
  libnppicom10 libnppidei10 libnppif10 libnppig10 libnppim10 libnppist10
  libnppisu10 libnppitc10 libnpps10 libnvblas10 libnvgraph10 libnvidia-ml-dev
  libnvjpeg10 libnvrtc10.1 libnvtoolsext1 libnvvm3 libthrust-dev libtinfo5
  libvdpau-dev node-html5shiv nsight-compute nsight-systems nvidia-cuda-dev
  nvidia-cuda-doc nvidia-cuda-gdb nvidia-cuda-toolkit nvidia-opencl-dev
  nvidia-profiler nvidia-visual-profiler ocl-icd-opencl-dev opencl-c-headers
  openjdk-8-jre openjdk-8-jre-headless
0 upgraded, 57 newly installed, 0 to remove and 127 not upgraded.
Need to get 1,398 MB of archives.

apt安装软件位置汇总:https://blog.csdn.net/u013276277/article/details/81033129
cuda路径添加:

 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-9.0/lib64
export PATH=$PATH:/usr/local/cuda-9.0/bin
export CUDA_HOME=$CUDA_HOME:/usr/local/cuda-9.0

/usr/bin下有nvcc,对应/usr/local/cuda/bin

nvcc的demo代码:https://linuxconfig.org/how-to-install-cuda-on-ubuntu-20-04-focal-fossa-linux

    CUDACXX: "/usr/local/cuda/bin/nvcc"
    CUDA_PATH: "/usr/local/cuda"
    CUDA_TOOLKIT_ROOT_DIR: "/usr/local/cuda"
    LD_LIBRARY_PATH: "/usr/local/cuda/lib64:/usr/local/cuda/lib64/stubs:$LD_LIBRARY_PATH"

pip install torch==1.4.0 -i https://pypi.doubanio.com/simple
python检测gpu的脚本:

import torch
flag = torch.cuda.is_available()
print(flag)

ngpu= 1
# Decide which device we want to run on
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda()) 

我发现darknet依然无法识别,于是将其卸载。
并尝试升级驱动:

sudo apt upgrade
[sudo] password for car: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  linux-headers-5.13.0-48-generic linux-hwe-5.13-headers-5.13.0-48
  linux-image-5.13.0-48-generic linux-modules-5.13.0-48-generic
  linux-modules-extra-5.13.0-48-generic
The following packages have been kept back:
  libnvidia-cfg1-510 libnvidia-compute-510 libnvidia-decode-510
  libnvidia-encode-510 libnvidia-extra-510 libnvidia-fbc1-510 libnvidia-gl-510
  linux-modules-nvidia-510-generic-hwe-20.04 nvidia-compute-utils-510
  nvidia-driver-510 nvidia-kernel-common-510 nvidia-kernel-source-510
  nvidia-utils-510 xserver-xorg-video-nvidia-510
The following packages will be upgraded:
  apport apport-gtk bash bind9-dnsutils bind9-host bind9-libs cups cups-bsd
  cups-client cups-common cups-core-drivers cups-daemon cups-ipp-utils
  cups-ppdc cups-server-common dbus-user-session distro-info-data dnsmasq-base
  dpkg e2fsprogs firefox firefox-locale-en fonts-opensymbol
  gir1.2-javascriptcoregtk-4.0 gir1.2-polkit-1.0 gir1.2-webkit2-4.0 gzip
  klibc-utils libarchive13 libc-bin libcups2 libcupsimage2 libdrm-amdgpu1
  libdrm-common libdrm-intel1 libdrm-nouveau2 libdrm-radeon1 libdrm2 libegl-mesa0 libevdev2 libext2fs2 libfreerdp-client2-2 libfreerdp2-2 libgbm1
  libgl1-mesa-dri libglapi-mesa libglx-mesa0 libinput-bin libinput10
  libjavascriptcoregtk-4.0-18 libjuh-java libjurt-java libklibc libldap-common
  libllvm12 libnss3 libntfs-3g883 libnvidia-common-510 libpolkit-agent-1-0
  libpolkit-gobject-1-0 libreoffice-base-core libreoffice-calc
  libreoffice-common libreoffice-core libreoffice-draw libreoffice-gnome
  libreoffice-gtk3 libreoffice-impress libreoffice-math libreoffice-ogltrans
  libreoffice-pdfimport libreoffice-style-breeze libreoffice-style-colibre
  libreoffice-style-elementary libreoffice-style-tango libreoffice-writer
  libridl-java libss2 libuno-cppu3 libuno-cppuhelpergcc3-3
  libuno-purpenvhelpergcc3-3 libuno-sal3 libuno-salhelpergcc3-3
  libunoloader-java libwebkit2gtk-4.0-37 libwinpr2-2 libxatracker2
  linux-generic-hwe-20.04 linux-headers-generic-hwe-20.04
  linux-image-generic-hwe-20.04 logsave mesa-vdpau-drivers mesa-vulkan-drivers
  networkd-dispatcher ntfs-3g openssl open orca policykit-1 python3-apport
  python3-paramiko python3-problem-report python3-uno rsync rsyslog snapd tar
  tcpdump thunderbird-locale-en-us tzdata uno-libs-private ure xz-utils
113 upgraded, 5 newly installed, 0 to remove and 14 not upgraded

理论上新内核安装之后不会对原来有任何影响。以防万一,立马重启看看n卡是否正常。

安装之后nvidia的版本情况如下:

car@car:~$ dpkg -l | grep nvidia
ii  libnvidia-cfg1-510:amd64                        510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA binary OpenGL/GLX configuration library
iU  libnvidia-common-510                            510.73.05-0ubuntu0.20.04.1            all          Shared files used by the NVIDIA libraries
ii  libnvidia-compute-510:amd64                     510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA libcompute package
ii  libnvidia-decode-510:amd64                      510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA Video Decoding runtime libraries
ii  libnvidia-encode-510:amd64                      510.47.03-0ubuntu0.20.04.1            amd64        NVENC Video Encoding runtime library
ii  libnvidia-extra-510:amd64                       510.47.03-0ubuntu0.20.04.1            amd64        Extra libraries for the NVIDIA driver
ii  libnvidia-fbc1-510:amd64                        510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA OpenGL-based Framebuffer Capture runtime library
ii  libnvidia-gl-510:amd64                          510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD
ii  linux-modules-nvidia-510-5.13.0-30-generic      5.13.0-30.33~20.04.1                  amd64        Linux kernel nvidia modules for version 5.13.0-30
ii  linux-modules-nvidia-510-generic-hwe-20.04      5.13.0-30.33~20.04.1                  amd64        Extra drivers for nvidia-510 for the generic-hwe-20.04 flavour
ii  linux-objects-nvidia-510-5.13.0-30-generic      5.13.0-30.33~20.04.1                  amd64        Linux kernel nvidia modules for version 5.13.0-30 (objects)
ii  linux-signatures-nvidia-5.13.0-30-generic       5.13.0-30.33~20.04.1                  amd64        Linux kernel signatures for nvidia modules for version 5.13.0-30-generic
ii  nvidia-compute-utils-510                        510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA compute utilities
ii  nvidia-driver-510                               510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA driver metapackage
ii  nvidia-kernel-common-510                        510.47.03-0ubuntu0.20.04.1            amd64        Shared files used with the kernel module
ii  nvidia-kernel-source-510                        510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA kernel source package
ii  nvidia-prime                                    0.8.16~0.20.04.1                      all          Tools to enable NVIDIA's Prime
ii  nvidia-settings                                 470.57.01-0ubuntu0.20.04.3            amd64        Tool for configuring the NVIDIA graphics driver
ii  nvidia-utils-510                                510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA driver support binaries
ii  screen-resolution-extra                         0.18build1                            all          Extension for the nvidia-settings control panel
ii  xserver-xorg-video-nvidia-510                   510.47.03-0ubuntu0.20.04.1            amd64        NVIDIA binary Xorg driver

升级之后果然亮度就不能调了,n卡驱动也没了

用run文件安装cuda驱动恢复了。但是prime无法使用,需要自己安装一个。
注意了,这时settings里面显示的驱动是不准的,哪怕显示llvm,依然有可能安装成功了。

黑屏问题解决:
sudo dpkg-reconfigure gdm3恢复正常
安装gdm3 ubuntu-desktop-full即可

关于安装cuda过程Error installing Cuda toolkit: Existing package manager installation of the driver found问题的解决办法:

~/Downloads/installpkg$ sudo sh cuda_11.7.0_515.43.04_linux.run --toolkit --override --silent

并在.bashrc文件里添加:

export PATH="/usr/local/cuda-8.0/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH"

最后的结论:
1.Nvidia驱动一定要去官网找对应的版本,用run文件安装
2.cuda同上

3.5 opencv

查看opencv版本:

pkg-config --modversion opencv

发现ros下自带opencv4.2了。为了保证opencv的稳定性,不打算装cuda版的opencv了

cmake -DWITH_GTK_2_X=ON -DWITH_CUDA=ON -DOPENCV_EXTRA_MODULES_PATH=/home/car/Downloads/installpkg/opencv-cuda/opencv_contrib-3.3.0/modules ..

报错:
error: ‘CODEC_FLAG_GLOBAL_HEADER’ was not declared in this scope
解决办法:https://blog.csdn.net/guo_lei_lamant/article/details/81568346
在/home/car/Downloads/installpkg/opencv-3.3.0/modules/videoio/src/cap_ffmpeg_impl.hpp添加:

#define AV_CODEC_FLAG_GLOBAL_HEADER (1 << 22)
#define CODEC_FLAG_GLOBAL_HEADER AV_CODEC_FLAG_GLOBAL_HEADER
#define AVFMT_RAWPICTURE 0x0020

报错:error: invalid conversion from ‘const char*’ to ‘char*’ [-fpermissive]
在/home/car/Downloads/installpkg/opencv-3.3.0/modules/python/src2/cv2.cpp

环境配置:https://blog.csdn.net/public669/article/details/99044895

对于vins等程序,必须在cmakelists指定版本为3
-std=c++11改为14(解决了pcl问题)
pcl/sophus都会有问题
并且要加上新的h文件
参照https://blog.csdn.net/weixin_43421058/article/details/119139425
https://zhuanlan.zhihu.com/p/418227536
以及

find_package(OpenCV 3 REQUIRED)

汇总在这里https://wenda.ncnynl.com/article/5
编译可以通过,运行会死
1.试试opencv3:set(OpenCV_DIR /home/nvidia/opencv-3.0.0/build)
2.cv::FONT_HERSHEY_SIMPLEX
3.-std=c++11改为14
4.#include
libopencv_imgcodecs.so.3.3, needed by /home/car/Downloads/installpkg/opencv-3.3.0/build/lib/libopencv_sfm.so.3.3.0, may conflict with libopencv_imgcodecs.so.4.2
依然运行报错
将源代码下的所有CMakeList.txt中的find_package(OpenCV REQUIRED),改成find_package(OpenCV 4 REQUIRED),可以成功!

主要参照的博客有:
关于opencv的纠正:https://wenda.ncnynl.com/article/5
https://blog.csdn.net/qq_41246375/article/details/109390019
https://blog.csdn.net/weixin_43421058/article/details/119139425
vinsfusion:https://blog.csdn.net/xiaojinger_123/article/details/121517771

3.6 SLAM依赖库

src文件夹下除去gtsam都安装成功了

sudo apt-get install intel-mkl

依然失败

eigen:

sudo cp -r /usr/include/eigen3/Eigen /usr/include
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include 

ceres的依赖如下:


sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev libgoogle-glog-dev libgtest-dev

sophus:
注意org版本对应的才是vinsfusion需要的sophus

vscode安装:https://developer.aliyun.com/article/759454

你可能感兴趣的:(opencv,ubuntu,自动驾驶)