Ubuntu18 解决问题记录

安装 python 3.7 并设置为默认 python 版本

安装

  1. 更新 apt 包列表,安装 software-properties-common:

    1
    2
    sudo apt update
    sudo apt install software-properties-common
  2. 添加 PPA

    1
    2
    sudo add-apt-repository ppa:deadsnakes/ppa
    提示输入 回车继续
  3. 安装 python 3.6

    1
    sudo apt install python3.6
  4. 验证

    1
    python3.6 --version

配置为默认 Python 版本

  1. 更新 update-alternatives

    1
    2
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
  2. 设置默认使用版本

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    sudo update-alternatives --config python
    此时将会出现下图

    Selection Path Priority Status
    ------------------------------------------------------------
    * 0 /usr/bin/python3.6 2 auto mode
    1 /usr/bin/python2.7 1 manual mode
    2 /usr/bin/python3.6 2 manual mode

    Press <enter> to keep the current choice[*], or type selection number:
    输入 2 即表示使用 python 3.7

    或者也可以通过下面方式设置 python 3.7
    sudo update-alternatives --set python /usr/bin/python3.6
  3. 验证

    1
    2
    3
    4
    python --version

    将显示:
    Python 3.7.4

误删 python 3.6 至启动只有命令行

  1. 首先在命令行登录成功,然后在命令行连接上网络,这里显示连接 wifi 方法

    1
    2
    3
    4
    5
    6
    7
    8
    # ① 确定 wifi 接口名
    $ nmcli d
    # ② 确定 wifi 功能打开
    $ nmcli r wifi on
    # ③ 显示可以连接的 wifi
    $ nmcli d wifi list
    # ④ 使用密码连接
    $ $ nmcli d wifi connect my_wifi password <password>
  2. 确定网络连接成功后,安装 ubuntu-desktop

    1
    $ sudo apt-get install ubuntu-desktop

批量修改当前目录下的文件后缀名

1
2
# 将后缀名为 txt 文件全部改为 md
for f in *.txt; do mv $f `basename $f .txt`.md; done;

动态查看 log

1
tail -f test.log

CentOS 7 服务器上运行 selenium

1
2
3
4
5
6
7
8
9
10
11
# 需要在相应位置添加 --headless --no-sandbox 两个参数
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
# options.add_argument('--disable-extensions')
# options.add_argument('--disable-gpu')

cookies = []
driver = webdriver.Chrome(CHROME_PATH, options=options)

后台运行 nohup

1
nohup bash test.sh >> ~/logs/test.log 2>&1 &
码哥 wechat
欢迎关注个人订阅号:「码上行动GO」