In this article, we will delve into the specifics of how to make Python point to Python3 in Ubuntu 20.04. This is particularly useful if you are working on projects that require Python3, but your system defaults to using Python2 when you use the
To make Python point to Python3 in Ubuntu 20.04, you can use either the
pyenv tool or the
python-is-python3 package. With
pyenv, you can manage multiple Python versions and set your desired version as the default. The
python-is-python3 package allows you to globally set
python3 in Ubuntu 20.04.
Understanding Python Versions
Before we dive into the process, it’s important to understand that Python2 and Python3 are different versions of the Python programming language. Python2 is an older version that is no longer actively maintained, while Python3 is the current version with ongoing support and updates.
In Ubuntu 20.04, Python3 comes pre-installed, but when you run the
python command in the terminal, it may not be pointing to Python3. This is because some older scripts and applications still rely on Python2, so the
python command is often linked to Python2 for compatibility reasons.
Checking Your Python Version
First, let’s check the current location of your
python3 executables. Open your terminal and type the following commands:
which command in Linux is used to identify the location of executables. The output of these commands will give you the paths to your
Changing Python to Point to Python3
python command is not pointing to Python3, you can change it using one of the following methods:
pyenv is a simple, powerful and cross-platform tool for managing multiple Python versions. If you have
pyenv installed, you can change the default Python version as follows:
- List the available Python versions: Run the
pyenv versionscommand to see a list of all Python versions installed on your system.
- Change the default Python version: Use the
pyenv globalcommand followed by the version number to set your desired Python version as the default.
pyenv global 3.8.5
In this example,
3.8.5 is the version number. Replace it with the version you want to set as default.
Using the python-is-python3 package
Ubuntu 20.04 provides a convenient package called
python-is-python3 that you can use to set
python to point to
- Install the package: Run the following command to install the package:
sudo apt install python-is-python3
sudo command is used to execute commands with root privileges.
apt is the package handling utility in Ubuntu.
install is the command to install a new package, and
python-is-python3 is the name of the package.
Verifying the Changes
After making the changes, you can verify that
python now points to
python3 by running the
which python command again. The output should now show the path to the
In this article, we have covered two methods to make Python point to Python3 in Ubuntu 20.04. The method you choose depends on your specific setup and requirements. If you are using
pyenv, it provides more flexibility in managing different Python versions for different projects. On the other hand, the
python-is-python3 package is a straightforward option for Ubuntu 20.04 users who want to globally set
Remember, it’s always a good practice to keep your Python version up to date and use the version that is most suitable for your projects. Happy coding!
It is important to make Python point to Python3 because Python2 is no longer actively maintained and Python3 is the current version with ongoing support and updates. Using Python3 ensures that you have access to the latest features, bug fixes, and security patches.
You can check your current Python version by opening your terminal and running the command
python --version. This will display the version number of the Python interpreter currently being used.
which command is used in Linux to identify the location of executables. In the context of this article, we use it to determine the paths to the
python3 executables on your system.
Yes, you can have both Python2 and Python3 installed on your system. Many systems, including Ubuntu 20.04, come with Python3 pre-installed. However, some older scripts and applications may still rely on Python2. It is important to ensure that your projects are using the correct Python version.
pyenv is a tool for managing multiple Python versions. It allows you to easily switch between different Python versions for different projects. This can be particularly useful when working on projects that require specific Python versions or when testing compatibility with different Python versions.
You can install
pyenv by following the instructions provided in the official
pyenv GitHub repository. The installation process usually involves cloning the repository, running a setup script, and adding the necessary configurations to your shell profile.
pyenv allows you to easily install different Python versions, including Python3, if they are not already installed on your system. You can use the
pyenv install command followed by the version number to install the desired Python version.
When changing the default Python version, it is important to consider the compatibility of your existing scripts and applications. Some older scripts may not be compatible with Python3, so it is advisable to test your projects thoroughly after making the change. Additionally, ensure that any dependencies or libraries used by your projects are compatible with the new Python version.
sudo is necessary when installing the
python-is-python3 package because it requires root privileges to make system-wide changes.
sudo allows you to execute commands with administrative privileges, ensuring that the package is installed correctly.
Yes, you can undo the changes and revert back to using Python2 as the default by following the same steps mentioned in this article, but setting the desired Python2 version instead. Alternatively, you can remove the
python-is-python3 package or modify your
pyenv configuration to switch back to Python2.