ติดตั้ง Python3.7
อัพเดท
sudo apt update
ตรวจสอบเวอร์ชันปัจจุบัน
$ python3 --version Python 3.6.9
ติดตั้ง Python3.7
sudo apt install python3.7
ตรวจสอบการติดตั้ง
$ python3.7 --version Python 3.7.5
กำหนด default python ให้เป็น Python3.7
sudo rm /usr/bin/python3 sudo ln -s /usr/bin/python3.7 /usr/bin/python3
ตรวจสอบเวอร์ชัน
$ python3 --version Python 3.7.5
ปัญหาเมื่อคำสั่ง python3 เป็นเวอร์ชัน 3.7
พอคำสั่ง python3 เป็นเวอร์ชัน 3.7 รัน apt update แล้ว error เลย
$ sudo apt update
Hit:1 http://th.archive.ubuntu.com/ubuntu bionic InRelease
Hit:2 http://th.archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:3 http://th.archive.ubuntu.com/ubuntu bionic-backports InRelease
Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
Traceback (most recent call last):
File "/usr/lib/cnf-update-db", line 8, in <module>
from CommandNotFound.db.creator import DbCreator
File "/usr/lib/python3/dist-packages/CommandNotFound/db/creator.py", line 11, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Reading package lists... Done
E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/lib/command-not-found/ -a -e /usr/lib/cnf-update-db; then /usr/lib/cnf-update-db > /dev/null; fi'
E: Sub-process returned an error code
วิธีแก้ไข
sudo apt remove python3-apt sudo apt install python3-apt
รัน apt update อีกทีจะใช้ได้ปกติละ
$ sudo apt update Hit:1 http://th.archive.ubuntu.com/ubuntu bionic InRelease Hit:2 http://th.archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:3 http://th.archive.ubuntu.com/ubuntu bionic-backports InRelease Hit:4 http://security.ubuntu.com/ubuntu bionic-security InRelease Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date.
ติดตั้ง pip3
sudo apt install python3-pip
ตรวจสอบเวอร์ชัน
$ pip3 --version pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.7)
อัพเดท pip3
python3 -m pip install --upgrade pip
ตรวจสอบเวอร์ชัน
$ pip3 --version WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip. Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue. To avoid this problem you can invoke Python with '-m pip' instead of running pip directly. pip 21.2.4 from /home/jack/.local/lib/python3.7/site-packages/pip (python 3.7)
$ python3 -m pip --version pip 21.2.4 from /home/jack/.local/lib/python3.7/site-packages/pip (python 3.7)
To list all the installed pip packages:
python3 -m pip list
To upgrade an installed package to the latest version:
python3 -m pip install --upgrade package_name
To uninstall a package run:
python3 -m pip uninstall package_name
ติดตั้ง python3.7-dev
ติดตั้ง python3-dev แบบระบุเวอร์ชันเป็น 3.7
sudo apt install python3.7-dev