"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Change the Default Python Version: Why Is My Terminal Still Using Python 2?

How to Change the Default Python Version: Why Is My Terminal Still Using Python 2?

Published on 2024-11-15
Browse:275

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.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3