为了部署opencv-python,安装了ubuntu20.04的虚拟机,很容易的安装了numpy、matplotlib、opencv模块。
但python是3.8.10版本,网上学习视频的版本为3.9,所以也进行了升级。
参考https://blog.csdn.net/wuxianbing2012/article/details/123532589, 完成了本次升级。
以下是参考博文的内容:
Upgrading Python in Linux
This article uses Ubuntu and its APT package manager to upgrade Python. If you are using a different Linux distribution, replace the apt
command with the appropriate command featured for your package manager.
Warning: Many Linux systems have Python 2 installed as the system version. Removing Python 2 could cause a system error. If you are planning to install Python 3 on Linux, install it alongside Python 2 and invoke it with the python3
command.
1. Start by updating the repositories:
sudo apt update
2. Next, install Python 3.9 by running:
sudo apt install python3.9
When prompted, type Y to start the installation.
3. Once Python installs, invoke the 3.9 version by running:
python3.9
4. However, checking the installation with the python3 --version
command still returns the old version. To fix this, you need to create a list of update alternatives. First, add the old version to the list with the command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.[old-version] 1
5. Now add the new version:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
6. Next, type the following command to configure the priority status of the versions:
sudo update-alternatives --config python3
The output displays the available choices and their assigned number (in the example below, the numbers are 0, 1, 2). Type the number of the the version you wish to use and press Enter.
7. If you are not planning to use the old version of Python, remove the symlink that contained the previous Python 3 version with:
sudo rm /usr/bin/python3
8. Then, replace the symlink with the new version:
sudo ln -s python3.9 /usr/bin/python3
9. Now, check the default version:
python3 --version
The output should confirm the successful installation and setup of the latest available version.
Why Should You Upgrade Python?
Since Python 3 was not a backward-compatible release, for a long time Python 2 remained the version of choice for those who wanted a stable development environment. Some services like Google App Engine did not support Python 3 for a long time.
However, given that the official support for the final Python 2.7 release has ended, upgrading to Python 3 is now strongly recommended. Python 3 is faster, and its syntax is more user-friendly.
If you already work with Python 3, upgrading to the latest point release gives you all the security updates and bug fixes.
标签:Ubuntu20.04,10,Python,sudo,version,python3.8,bin,python3,usr From: https://www.cnblogs.com/xihong2014/p/17339186.html