无法安装指定版本Python求助:执行sudo apt-get install python>=3.6.6获3.5.3
Hey there! I’ve dealt with this exact problem a few times, so let me walk you through what’s going wrong and how to fix it.
Why this happens
The apt-get tool doesn’t support version range syntax like >=3.6.6—when you run sudo apt-get install python>=3.6.6, it just looks for the package named python in your system’s repositories. On older Debian/Ubuntu releases, this package is typically mapped to Python 3.5.x, which is why you’re ending up with 3.5.3 instead of the version you want.
How to install Python 3.6.6+ correctly
Here are the steps to get the right version installed:
Check available versions in your default repos
First, update your package list to make sure you have the latest info:sudo apt updateThen, see if Python 3.6+ is available directly by running:
apt list python3.*If you see
python3.6(or higher) in the list, install it with:sudo apt-get install python3.6Replace
3.6with the specific version you need (like3.7,3.8, etc.) if it’s available.Add a third-party repo if needed
If your default repos don’t have Python 3.6+, thedeadsnakesPPA is a reliable source for newer Python versions. Here’s how to use it:- Install the required tools to add PPAs:
sudo apt install software-properties-common - Add the deadsnakes repo:
sudo add-apt-repository ppa:deadsnakes/ppa - Update your package list again:
sudo apt update - Now install your desired Python version:
sudo apt install python3.6
- Install the required tools to add PPAs:
Set the default Python version (optional)
If you want to make the newly installed Python the defaultpython3on your system, useupdate-alternatives:- Register the installed versions with alternatives:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2 - Select the default version by running:
sudo update-alternatives --config python3
Just follow the on-screen prompt to pick the number corresponding to Python 3.6.
- Register the installed versions with alternatives:
That should get you the Python version you need! Let me know if you run into any snags along the way.
内容的提问来源于stack exchange,提问作者user12

