Home >Backend Development >Python Tutorial >How to Change the Default Python Version: Why Is My Terminal Still Using Python 2?
How to Change Default Python Version: Beyond Compatibility Issues
You installed Python 3.2 and, despite running the Update Shell Profile command, Terminal still shows Python 2.6.1. This discrepancy can be confusing, so let's explore how to change your default Python version.
Historical Context: Backward Compatibility and Multiple Versions
In the past, Python2 was prevalent. The release of Python3 introduced significant changes, breaking backward compatibility. To maintain compatibility for existing scripts, Python2 installations remained intact, and the latest version was typically accessed via python3.
Current Practices: User-Defined Default and Virtual Environments
Today, many operating systems allow users to set a custom default for the python command. This offers more flexibility as most software now explicitly refers to python2 or python3.
Shell Alias: A Convenient Local Option
You can create a custom alias in your shell to make python launch python3. However, this approach is only convenient on your local computer and requires manually typing the alias each time.
Multiple 3. or 2. Versions: Using Your OS's Management Tools
If you have multiple Python versions installed, use your OS's package manager to track and possibly remove older versions. If you require multiple versions, configure your $PATH variable to prioritize the desired default or use update-alternatives.
Understanding $PATH and Symbolic Links
$PATH is an environment variable that determines which directories are searched for executable files. By default, most systems have /usr/bin (or similar) in $PATH, which typically contains symbolic links to various Python versions.
The above is the detailed content of How to Change the Default Python Version: Why Is My Terminal Still Using Python 2?. For more information, please follow other related articles on the PHP Chinese website!