Ubuntu系统---安装English版本之后的一些工作

                                                                  Ubuntu系统---安装English版本之后的一些工作

安装完Ubuntu系统English版本之后:
-----------------------------------------------------------------------------------
(1)设置网络。设置IP,保证能上网。192.168.1.191; 255.255.255.0;192.168.1.1
-----------------------------------------------------------------------------------
(2)安装一个中文输入法,方便日常工作。@https://blog.csdn.net/suifenghahahaha/article/details/78723733 ,Ubuntu 16.04安装iBus中文输入法pinyin及问题,能用就行,也不一定非要搜狗输入法。
-----------------------------------------------------------------------------------
(3)CUDA+驱动+cuDNN+添加到系统环境中
-----------------------------------------------------------------------------------
(4)禁止内核更新
查看内核:sudo dpkg --get-selections  |  grep  'linux'
...
linux-generic-hwe-16.04                install
linux-headers-4.15.0-45                install
linux-headers-4.15.0-45-generic            install
linux-headers-generic-hwe-16.04            install
linux-image-4.15.0-45-generic            install
linux-image-generic-hwe-16.04            install
linux-libc-dev:amd64                install
linux-modules-4.15.0-45-generic            install
linux-modules-extra-4.15.0-45-generic        install
linux-signed-generic-hwe-16.04            install
linux-sound-base                install

执行:
sudo apt-mark hold linux-headers-4.15.0-45
linux-headers-4.15.0-45-generic
linux-image-4.15.0-45-generic
linux-modules-4.15.0-45-generic
linux-modules-extra-4.15.0-45-generic

echo "linux-headers-4.15.0-45 hold" | dpkg --set-selections
echo "linux-headers-4.15.0-45-generic hold" | dpkg --set-selections
echo "linux-image-4.15.0-45-generic hold" | dpkg --set-selections
echo "linux-modules-4.15.0-45-generic hold" | dpkg --set-selections
echo "linux-modules-extra-4.15.0-45-generic hold" | dpkg --set-selections

-----------------------------------------------------------------------------------
(5)安装好opencv + 查看安装的版本
pkg-config --modversion opencv

u@u160406:~$ pkg-config --modversion opencv
3.4.2

-----------------------------------------------------------------------------------
(6)查看自带的python版本
u@u160406:~$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
u@u160406:~$ python3
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
u@u160406:~$

-----------------------------------------------------------------------------------
(7)设置系统里python的默认版本
    显示说明,python默认的是Python 2.7.12,但还存在Python 3.5.2。
    接着,可以罗列出所有可用的 python 替代版本信息:
    update-alternatives --list python
    提示:update-alternatives: error: no alternatives for python
    如果出现以上所示的错误信息,则表示 Python 的替代版本尚未被 update-alternatives 命令识别。
    想解决这个问题,需要更新一下替代列表,将 python2.7 和 python3.5 放入其中。打开终端分别输入下面两条命令:
    $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
    $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
    #sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
    #sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
    然后再终端输入:
    python
    如果无误,此时python版本应该切换到默认的python3了。

    如果需要重新切换python版本,只需要在终端输入:
    sudo update-alternatives --config python
    然后选者你需要的python版本,输入序号回车即可。

  查看默认版本
    python --version
  上述命令中因为我们设置 /usr/bin/python3.5 设置的优先级为2 所以update-alternatives命令自己设置3.5为默认。再次显示Python代替版本信息:
    update-alternatives --list python
  切换版本:
    update-alternatives --config python


  移除替代版本,一旦系统中不再存在某个 Python 的替代版本时,我们可以将其从 update-alternatives 列表中删除掉。例如,我们可以将列表中的 python2.7 版本移除掉。
    wp@wp-MS-7519:~$ update-alternatives --remove python /usr/bin/python2.7
    update-alternatives: removing manually selected alternative - switching python to auto mode
    update-alternatives: using
    /usr/bin/python3.4 to provide
    /usr/bin/python (python)
    in auto mode

-----------------------------------------------------------------------------------
(8)配python-opencv
若无pip,先安装pip3,执行命令: sudo apt install python3-pip
安装依赖项,安装libopencv-dev依赖包,运行命令: sudo apt install libopencv-dev
安装opencv-python库
1. 直接安装最新版:sudo pip3 install opencv-python
2. 或者可以进行指定版本安装:pip3 install opencv_python==版本号
    由于我这里是安装opencv3.4.2,目前的最新版是3.4.2.16
    所以直接执行:pip3 install opencv_python==3.4.2.16

【备注,这一步的提前准备工作】
通常情况下,你的电脑里如果安装了python2.x也同时安装了python3.x,那么应该就会有两个pip。一个是pip2,另一个是pip3。好吧,可能还有一个既没有2,也米有3的pip,一般情况下,pip==pip2。
1、python下发现无pip,安装一个pip:  pip --version
The program 'pip' is currently not installed. You can install it by typing:
sudo apt install python-pip
py2执行:  sudo apt install python-pip
py3执行:  sudo apt install python3-pip

2、更新pip版本:
py2执行: pip install --upgrade pip  或者 python -m pip install --upgrade pip
py3执行: pip3 install --upgrade pip 或者 python3 -m pip install --upgrade pip

3、查看python版本:
pip --version
pip -V

4、问题解决
>>>>在默认py3下运行,会报错:
u@u160406:~$ pip -V
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name 'main'
u@u160406:~$ sudo gedit /usr/bin/pip

记得系统的默认py版本在执行相关的操作命令:
sudo gedit /usr/bin/pip3
//修改前
from pip import main
if __name__ == '__main__':
    sys.exit(main())
//修改后#@wp20190906 add
from pip import __main__
if __name__ == '__main__':  
    sys.exit(__main__._main())

在执行下列民令就不会报错了:
pip3 --version
pip3 -V

---------------------------python3安装opencv_python==3.4.2
u@u160406:~$ pip3 install opencv_python==3.4.2
Collecting opencv_python==3.4.2
  ERROR: Could not find a version that satisfies the requirement opencv_python==3.4.2 (from versions: 3.1.0.0, 3.1.0.1, 3.1.0.2, 3.1.0.3, 3.1.0.4, 3.1.0.5, 3.2.0.6, 3.2.0.7, 3.2.0.8, 3.3.0.9, 3.3.0.10, 3.3.1.11, 3.4.0.12, 3.4.0.14, 3.4.1.15, 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 4.0.0.21, 4.0.1.23, 4.0.1.24, 4.1.0.25, 4.1.1.26)
ERROR: No matching distribution found for opencv_python==3.4.2
u@u160406:~$ pip3 install opencv_python==3.4.2.16


ERROR: No matching distribution found for numpy>=1.11.1 (from opencv_python==3.4.2.16)
查看Numpy版本:
python3
import numpy
print numpy.__version__

pip show numpy 查看numpy版本;
pip install -U numpy==1.12.0,降低numpy的版本

执行: pip3 install numpy==1.9.3
报错: Consider using the `--user` option or check the permissions.
改执行: sudo pip3 install numpy==1.9.3  ????
...
Installing collected packages: numpy
Successfully installed numpy-1.17.1

执行: sudo pip3 install opencv_python==3.4.2.16
...
Successfully installed opencv-python-3.4.2.16

u@u160406:~$ python
Python 3.5.2 (default, Nov 12 2018, 13:43:14)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.2'
>>>

---------------------------python2安装opencv_python==3.4.2
pip install opencv_python==3.4.2 不好用
python2 -m pip install opencv-python 不好用
pip install --user -U numpy 升级numpy的版本
然后查看python3的安装路径,打开终端输入: which python3 #查看python3的安装路径
pip install --user opencv_python==3.4.2
pip install --user opencv_python==3.4.2.17
...
Successfully installed opencv-python-3.4.2.17
u@u160406:~$ python
Python 2.7.12 (default, Nov 12 2018, 14:36:49)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.4.2'
>>>

(9)不管是用pip装什么模块,前面尽量不要加sudo
sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。这样不仅减少了root用户的登录 和管理时间,同样也提高了安全性。sudo不是对shell的一个代替,它是面向每个命令的。

python 通过pip安装程序包的时候提示:Consider using the `--user` option or check the permissions.
原因不明,解决方法,如:
1、通过pip install pandas --user 安装
2、通过pip install pandas --user pandas安装

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