ubuntu---2020.04.23重装系统记录(篇3)

本篇记录:重装系统记录中间会遇到的一些细节问题与参考解决方式

*******************************************************************
*******************************************************************
【问题1】中断一些更新,再执行其他程序时,会遇到
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

E: Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)
E: Unable to lock directory /var/lib/apt/lists/

【解决】
方式一:
$ sudo rm /var/lib/apt/lists/lock
$ sudo rm /var/cache/apt/archives/lock
$ sudo rm /var/lib/dpkg/lock

方式二:
1、运行下面的命令来生成所有含有 apt 的进程列表
命令:ps -A | grep apt

2、杀死进程
命令:kill -9 2814


*******************************************************************
*******************************************************************
【问题2】sudo apt-get update特别慢更新不了

【解决】
打开terminal,备份原文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list.old
cd /etc/apt
sudo gedit sources.list
(sudo gedit /etc/apt/sources.list )
添加如下内容【去阿里云上 https://developer.aliyun.com/mirror/ubuntu,查看适合 ubuntu 16.04 的源配置如下】:
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

也可参考@ https://www.cnblogs.com/Eric-Shenblog/p/10862027.html
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

然后:
sudo apt-get update   #更新软件列表。
sudo apt-get upgrate  #更新软件。这一步,如果按提示选择了Y,可能会耗时很长,耐心等待。


@ https://www.cnblogs.com/X-knight/p/10598498.html
如何更改源:东北大学、清华大学、阿里云



*******************************************************************
*******************************************************************
【问题3】sudo apt-get update 报错
Get:103 http://mirrors.aliyun.com/ubuntu bionic-backports/universe DEP-11 64x64 Icons [29 B]               
Fetched 58.6 MB in 8s (6,754 kB/s)                                                                         

(appstreamcli:8043): GLib-CRITICAL **: g_strchug: assertion 'string != NULL' failed

(appstreamcli:8043): GLib-CRITICAL **: g_strchomp: assertion 'string != NULL' failed

(appstreamcli:8043): GLib-CRITICAL **: g_strchug: assertion 'string != NULL' failed

(appstreamcli:8043): GLib-CRITICAL **: g_strchomp: assertion 'string != NULL' failed

(appstreamcli:8043): GLib-CRITICAL **: g_strchug: assertion 'string != NULL' failed

(appstreamcli:8043): GLib-CRITICAL **: g_strchomp: assertion 'string != NULL' failed
AppStream cache update completed, but some metadata was ignored due to errors.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
1490 packages can be upgraded. Run 'apt list --upgradable' to see them.

【解决】
解决办法1:
sudo sed -i -e 's/bionic/xenial/g' /etc/apt/sources.list  
@https://www.cnblogs.com/iBoundary/p/12679186.html

解决办法2:
sudo apt purge libappstream4
@https://blog.csdn.net/qq_41972382/article/details/95720761
@https://blog.csdn.net/zhushixia1989/article/details/104550890/




*******************************************************************
*******************************************************************
【问题4】sudo apt-get install XXX 时, 会出现 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

【解决】
解决办法1:源的问题,更改后更新,参考“【问题2】sudo apt-get update特别慢更新不了”

解决办法2:网络的问题
网关错误拦截了数据包或者防火墙故意将其屏蔽在外(比方update 包含有google-chrome浏览器的source时候,ip 会自动重定向至6.6.6.6) 
    sudo gedit /etc/resolv.conf
    添加:
nameserver 8.8.8.8
nameserver 223.5.5.5
nameserver 223.6.6.6

@ https://www.cnblogs.com/X-knight/p/10598076.html


*******************************************************************
*******************************************************************
【问题5】sudo apt-get install XXX 安装不好使的时候,使用sudo aptitude install XXX,也可以在 source.list 中更新国内源

【解决】
sudo apt-get install iptux
sudo apt-get install aptitude

Ubuntu如何更新软件源@ https://jingyan.baidu.com/article/624e74590223bc34e8ba5a3b.html


*******************************************************************
*******************************************************************
【问题5】Ubuntu 16.04安装iBus中文输入法pinyin及问题

【解决】@ https://blog.csdn.net/suifenghahahaha/article/details/78723733



*******************************************************************
*******************************************************************
【问题6】如果系统的内核不是最新的,如何更新到最新稳定版本的内核?

【解决】
Ubuntu 18.04 LTS - Bionic Beaver
DESKTOP:
 sudo apt-get install --install-recommends linux-generic-hwe-18.04 xserver-xorg-hwe-18.04  
SERVER:
 sudo apt-get install --install-recommends linux-generic-hwe-18.04


Ubuntu 16.04 LTS - Xenial Xerus
DESKTOP
sudo apt-get install --install-recommends linux-generic-hwe-16.04 xserver-xorg-hwe-16.04
SERVER
 sudo apt-get install --install-recommends linux-generic-hwe-16.04

@https://blog.csdn.net/wangweiwells/java/article/details/88279537


*******************************************************************
*******************************************************************
【问题7】禁止更新内核,需时间来验证
sudo apt-mark hold linux-image-x.xx.x-xx-generic
sudo apt-mark hold linux-image-extra-x.xx.x-xx-generic

【解决】
sudo apt-mark hold linux-image-4.15.0-96-generic
sudo apt-mark hold linux-image-extra-4.15.0-96-generic

sudo apt-mark hold linux-modules-extra-4.15.0-96-generic


u@u1604:~$ sudo apt-mark hold linux-image-extra-4.15.0-96-generic
E: 无法定位软件包 linux-image-extra-4.15.0-96-generic
E: 无法按照 glob ‘linux-image-extra-4.15.0-96-generic’ 找到任何软件包
E: 无法按照正则表达式 linux-image-extra-4.15.0-96-generic 找到任何软件包
E: 没有发现匹配的软件包
sudo apt-get install linux-image-extra-4.15.0-96-generic

一条语句禁止内核更新:
sudo apt-mark hold linux-image-4.15.0-96-generic linux-modules-extra-4.15.0-96-generic linux-headers-4.15.0-96-generic    



*******************************************************************
*******************************************************************
【问题8】安装新内核
1. 执行以下命令安装
sudo apt-get install linux-image-extra-4.15.0-96-generic

2. 执行以下命令查看是否安装成功
dpkg -l | grep 4.15.0-96-generic

3. 保存退出,然后执行以下命令更新 Grub 引导
sudo update-grub

4.将其他版本的内核删除,如(对deinstall的需要用dpkg卸载):
sudo apt-get remove linux-headers-4.15.0-33
sudo dpkg -P linux-image-4.8.0-36-generic
sudo apt-get purge linux-image-<版本号> 命令    
    
5.查看Linux中当前使用的内核:
使用 uname -a 或者 uname -r  命令
    
6.查看Linux中安装了哪些内核:
使用 dpkg --get-selections | grep linux  或者 dpkg --list |grep linux 命令    
    
7.需要知道的是,内核映像文件主要包括以下类型:

linux-image-版本号:内核映像文件
linux-headers-版本号:内核头文件
linux-image-extra-版本号:内核扩展文件

8.更新grub文件:
sudo update-grub


-----------------------------------------------
安装的话,需要注意,安装内核需要安装image和header,不能只安装其中一个。
比如我现在安装一个linux-image-4.8.0-58-generic,
就必须还要安装一个linux-headers-4.8.0-58-generic。

sudo apt-get install linux-image-4.15.0-88-generic
sudo apt-get install linux-headers-4.15.0-88-generic
sudo apt-get install linux-image-extra-4.15.0-88-generic
sudo apt-get install linux-modules-extra-4.15.0-96-generic

sudo apt-get install linux-image-4.15.0-88-generic linux-headers-4.15.0-88-generic




*******************************************************************
*******************************************************************
【问题9】opencv的下载与编译

【(1)下载】
https://github.com/opencv/opencv/archive/3.4.2.zip

wget -c https://github.com/opencv/opencv/archive/3.4.2.zip
wget -c https://github.com/opencv/opencv_contrib/archive/3.4.2.zip
注意:下载的是同名,但是不同的文件,在不同的文件里进行下载并解压。

【(2)编译】
sudo apt-get install build-essential

sudo apt-get install cmake git libgtk2.0-dev ffmpeg libopencv-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev liblapacke-dev libxvidcore-dev libx264-dev libatlas-base-dev gfortran

cd opencv-3.4.2
mkdir build  && cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON-D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=/home/u/opencv-3.4.2/opencv_contrib-3.4.2/modules -D BUILD_EXAMPLES=ON ..

sudo make  (sudo make all -j12 加快速度)
sudo make install

-------------------------
[100%] Linking CXX executable ../../bin/example_tutorial_display_image
[100%] Built target example_tutorial_cloning_gui
[100%] Linking CXX executable ../../bin/example_cpp_openni_capture
[100%] Built target example_tutorial_display_image
[100%] Built target example_cpp_openni_capture
[100%] Linking CXX shared module ../../lib/cv2.so
[100%] Built target opencv_python2
u@u1604:~/opencv-3.4.2/build$
u@u1604:~/opencv-3.4.2/build$
u@u1604:~/opencv-3.4.2/build$
u@u1604:~/opencv-3.4.2/build$ sudo make install


【(2)编译---会遇到的细节问题】
cmake -D ...........

(1)CMake Error at /usr/share/cmake-3.5/Modules/FindQt4.cmake:1326 (message):
  Found unsuitable Qt version "" from NOTFOUND, this code requires Qt 4.x

sudo apt-get install qt4-default

重新编译,即可成功``。
或者:
用QT5编译
```py
catkin_make -DUseQt5=ON -j2

(2)解决GitHub的raw.githubusercontent.com无法连接问题  @https://www.cnblogs.com/sinferwu/p/12726833.html
sudo gedit /etc/hosts

# wp2020.4.23 for opencv-sudo-make error of boostdesc_bgm.i
#151.101.76.133 raw.githubusercontent.com
199.232.68.133 raw.githubusercontent.com


iP或域名查询
raw.githubusercontent.com服务器iP:
当前解析:
日本 东京 151.101.108.133
日本 东京 151.101.228.133
美国 151.101.0.133
保留地址 0.0.0.0
中国 香港 151.101.76.133
历史解析记录:
2017-04-13-----2020-04-23 151.101.76.133
2017-12-14-----2020-04-23 151.101.228.133
2018-10-11-----2020-04-23 151.101.108.133


*******************************************************************
*******************************************************************
【问题10】python2 与 python3 的切换

update-alternatives --list python

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1

update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

update-alternatives --list python

update-alternatives --config python


*******************************************************************
*******************************************************************
【问题11】执行python3 -m pip install 模块名 、sudo pip3 install XXX,
会提示:from pip import main ImportError: cannot import name 'main'

u@u1604:~$ sudo pip3 install -r requirements/requirements-linux-python3.txt
Traceback (most recent call last):
  File "/usr/bin/pip3", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'


【解决】
sudo gedit /usr/bin/pip3
#!/usr/bin/python3
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.

# python2
'''
from pip import main
if __name__ == '__main__':
    sys.exit(main())
'''

# python3
from pip import __main__
if __name__ == '__main__':  
    sys.exit(__main__._main())


*******************************************************************
*******************************************************************
安装完后,查看细节版本:
(1)查看NVIDIA驱动安装版本
验证是否安装成功,执行:nvidia-smi 。

(2)查看CUDA安装版本
CUDA一般安装在 /usr/local/cuda/ 路径下,该路径下有一个version.txt文档,里面记录了cuda的版本信息。
执行命令:cat /usr/local/cuda/version.txt ,即可查询。
也可以使用:nvcc --version  ,进行查询。

(3)查看CuDNN版本
CuDNN的信息在其头文件里:
cat  /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2 , 即可查询。

(4)查询OpenCV版本 :
pkg-config opencv --modversion 


(5)查询当前使用的kernel版本 :
uname -r

(6)查询python版本 :
python

(6)查询gcc版本 :
gcc --version

原文地址:https://www.cnblogs.com/carle-09/p/12765254.html