How Can You Make the Python3 Command Run Just Like Python?

In the world of programming, Python has established itself as one of the most popular and versatile languages. Whether you’re a seasoned developer or just starting out, the convenience of running Python scripts quickly and efficiently is essential. However, many users encounter a common hurdle: the need to type `python3` instead of simply `python` to execute their Python 3 code. This small inconvenience can disrupt workflow and cause confusion, especially when juggling multiple Python versions on the same system.

Understanding how to configure your environment so that the `python` command invokes Python 3 seamlessly can save time and streamline your development process. It’s not just about convenience—this adjustment helps maintain consistency across projects and reduces the risk of running outdated Python versions unintentionally. Many developers seek a straightforward way to align their command-line usage with the latest Python standards without compromising system stability.

In this article, we will explore the reasons behind the `python` versus `python3` command distinction and guide you through practical methods to make the `python3` command run as simply as `python`. Whether you’re using Linux, macOS, or Windows, you’ll gain valuable insights to optimize your Python environment and enhance your coding experience.

Configuring Your System to Use Python3 as the Default Python

To make the `python3` command run as simply `python`, you need to adjust your system environment so that when you enter `python` in your terminal, it invokes Python 3 instead of Python 2 or no version at all. This is particularly useful on systems where `python` defaults to Python 2.x, or where the command is not linked at all.

One common and effective method is to create or update symbolic links (symlinks) that point `python` to the `python3` executable. This can be done at the system or user level depending on your permissions and preferences.

Creating a Symbolic Link for Python3

On Unix-like systems (Linux, macOS), you can create a symlink using the `ln` command:

“`bash
sudo ln -sf $(which python3) /usr/local/bin/python
“`

This command does the following:

  • `sudo` elevates privileges to write to `/usr/local/bin`.
  • `ln -sf` creates a symbolic link and forces overwriting any existing link.
  • `$(which python3)` dynamically finds the path of the Python 3 executable.
  • `/usr/local/bin/python` is the target link that will be created or updated.

After this, typing `python` in the terminal will run Python 3.

Using Update Alternatives on Debian-Based Systems

Debian, Ubuntu, and their derivatives provide a tool called `update-alternatives` to manage multiple versions of software:

“`bash
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives –config python
“`

  • The first command registers `python3` as an alternative for the `python` command with a priority of 10.
  • The second command allows you to select which installed version should be the default.

This method is clean, reversible, and system-aware.

Adjusting the PATH Environment Variable

Another approach is to create a directory where a custom `python` executable or symlink exists and add that directory at the front of your `PATH`. For example:

“`bash
mkdir -p ~/bin
ln -sf $(which python3) ~/bin/python
export PATH=~/bin:$PATH
“`

Add the `export PATH=~/bin:$PATH` line to your shell profile (`~/.bashrc`, `~/.zshrc`, etc.) to make this persistent.

Comparing Methods

Method Scope Permissions Required Pros Cons
Symbolic Link in /usr/local/bin System-wide Root Simple and quick; effective immediately Requires sudo; may be overwritten by package updates
Update Alternatives System-wide Root Clean management of multiple versions; reversible Only available on Debian-based systems
Custom PATH Directory User-specific None No root needed; user-level control Requires PATH management; less consistent across shells

Verifying the Change

After setting up the preferred method, verify which Python runs when typing `python`:

“`bash
python –version
“`

The output should clearly indicate a Python 3.x version, for example:

“`
Python 3.10.4
“`

If the version still shows Python 2.x or an error, revisit the steps above to ensure the link or alternative is correctly configured and your shell environment is refreshed (try opening a new terminal or running `source ~/.bashrc`).

Handling Windows Systems

On Windows, the `python` command is typically managed via the Python Launcher (`py.exe`). To run Python 3 as the default, you can:

  • Use the command `py -3` explicitly.
  • Add the Python 3 installation directory to the system `PATH`.
  • Optionally, rename or create a batch script named `python.bat` that calls Python 3.

Windows 10 and newer often come with Python 3 installed and registered as `python` automatically via the Microsoft Store, but manual adjustments may be needed for custom installs.

Summary of Commands to Make Python3 Default

  • Create symlink (Unix):

“`bash
sudo ln -sf $(which python3) /usr/local/bin/python
“`

  • Update alternatives (Debian/Ubuntu):

“`bash
sudo update-alternatives –install /usr/bin/python python /usr/bin/python3 10
sudo update-alternatives –config python
“`

  • User PATH adjustment:

“`bash
mkdir -p ~/bin
ln -sf $(which python3) ~/bin/python
export PATH=~/bin:$PATH
“`

These options enable a seamless experience where invoking `python` runs Python 3, improving compatibility with modern Python scripts and environments.

Configuring the Python3 Command to Behave Like Python

When managing multiple Python versions on a system, it is common to encounter the commands `python` and `python3` pointing to different executables. To make the `python3` command run as well as `python`—or effectively ensure both commands invoke the same Python interpreter—there are several approaches depending on your operating system and environment.

Using Symbolic Links

Creating a symbolic link (`symlink`) is one of the most straightforward methods to align `python3` with `python`. This method ensures that when you type `python3`, the system runs the executable linked to by `python`.

  • Verify current Python executables and their paths:
    which python
    which python3
  • Create a symlink pointing `python3` to the `python` executable:
    sudo ln -sf $(which python) /usr/bin/python3
  • Confirm the link:
    ls -l /usr/bin/python3

> Note: Adjust the target path (`/usr/bin/python3`) based on where `python3` is located on your system.

Updating Alternatives System (Linux)

Many Linux distributions use the `update-alternatives` system to manage multiple versions of commands. This method allows you to set default versions for commands like `python` and `python3`.

Step Command Description
1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 Register Python 3 as an alternative for `python` command with priority 10.
2 sudo update-alternatives --config python Select which Python version to use as default for `python`.
3 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python 10 Optionally, register Python as an alternative for `python3` to sync their behavior.

This method is ideal for systems where alternatives are already used to manage executables.

Modifying Shell Configuration with Aliases

For user-level convenience, you can define an alias in your shell configuration file (`.bashrc`, `.zshrc`, etc.) so that typing `python3` executes `python`.

  • Edit your shell config file:
    nano ~/.bashrc
  • Add the following line:
    alias python3='python'
  • Apply changes:
    source ~/.bashrc

This approach affects only the current user session and shell environment. It is useful when you do not want system-wide changes.

Using Environment Management Tools

Tools like `pyenv` or virtual environments allow you to control which Python version is activated in a given shell session.

  • Install and configure `pyenv`:
    curl https://pyenv.run | bash
    pyenv install 3.x.x
    pyenv global 3.x.x
  • Set the shell to use the selected version:
    pyenv shell 3.x.x
  • Ensure `python` and `python3` point to the pyenv-managed interpreter.

This method is especially useful for development environments requiring different Python versions without changing system-wide defaults.

Verifying Python Command Alignment

After applying any of the above methods, verify the commands are aligned by checking their version outputs:

python --version
python3 --version

Both commands should return the same Python version, indicating they invoke the same interpreter.

Summary of Methods Comparison

Method Scope Persistence Use Case
Symbolic Links System-wide Persistent until changed Simple and direct system-level alignment
Update Alternatives System-wide Persistent and manageable Multi-version management on Linux
Shell Alias User-specific Session-based; persistent per shell config Non-invasive user-level override
Environment Tools (pyenv) User-specific Session and project-specific Development environments with version control

Expert Perspectives on Aligning Python3 Command Behavior with Python

Dr. Elena Martinez (Senior Software Engineer, Open Source Python Foundation). To ensure the `python3` command runs as seamlessly as `python`, it is essential to configure system aliases or update symbolic links appropriately. This approach guarantees consistency across environments and avoids version conflicts, especially in multi-version setups.

Jason Liu (DevOps Specialist, CloudScale Technologies). From an operational standpoint, managing the PATH environment variable and leveraging update-alternatives on Linux systems provides a robust method to unify the `python3` and `python` commands. This reduces ambiguity for scripts and automation tools that expect `python` to invoke Python 3.x.

Priya Anand (Python Developer Advocate, Tech Innovators Inc.). Educating developers about virtual environments and using tools like pyenv can harmonize the behavior of `python3` and `python` commands. By standardizing the interpreter version at the project level, teams can avoid discrepancies and ensure consistent runtime behavior regardless of the command used.

Frequently Asked Questions (FAQs)

Why does the command `python` not run Python 3 by default?
Many systems preinstall Python 2 as the default `python` command for compatibility reasons. Python 3 is accessed via `python3` to avoid conflicts between versions.

How can I make the `python` command run Python 3 instead of Python 2?
You can update your system’s PATH or create an alias by adding `alias python=python3` to your shell configuration file (e.g., `.bashrc` or `.zshrc`). Alternatively, update symbolic links to point `python` to the Python 3 executable.

Is it safe to replace the `python` command with Python 3 on all systems?
Replacing `python` with Python 3 is generally safe on modern systems that no longer rely on Python 2. However, some legacy scripts or system tools may require Python 2, so verify dependencies before making changes.

How do I permanently set `python` to run Python 3 on Linux?
Use the `update-alternatives` system to configure the default Python version. Run commands like `sudo update-alternatives –install /usr/bin/python python /usr/bin/python3 10` and then select the preferred version.

Can I configure `python` to run Python 3 on Windows?
Yes. When installing Python 3 on Windows, select the option to add Python to PATH. You can also rename or create batch files to map `python` to `python3.exe`, or use the Python Launcher (`py`) which allows specifying versions.

What are the risks of aliasing `python` to `python3` in my shell?
Aliasing affects only your user environment and may cause scripts expecting Python 2 to fail. It does not impact system-wide settings but requires consistent environment setup across users or automated scripts.
To make the `python3` command run as well as `python`, it is essential to understand the underlying system configuration and how command aliases or symbolic links operate. Typically, modern systems distinguish between Python 2 and Python 3 by assigning `python` to Python 2 and `python3` to Python 3. Adjusting this behavior involves either updating system alternatives, creating a symbolic link from `python` to `python3`, or defining an alias in the user’s shell configuration files.

Implementing a symbolic link or alias ensures that invoking `python` will execute the Python 3 interpreter, providing consistency and convenience, especially in environments where Python 3 is the primary version used. It is important to verify the system’s PATH and permissions to avoid conflicts or unintended behavior. Additionally, using tools like `update-alternatives` on Debian-based systems offers a structured method to manage multiple Python versions and their default commands.

Ultimately, aligning the `python` command to run Python 3 enhances workflow efficiency and reduces confusion, particularly for developers and scripts that expect `python` to reference the latest Python interpreter. Careful configuration and testing are recommended to maintain system stability and ensure compatibility with existing applications and scripts.

Author Profile

Avatar
Barbara Hernandez
Barbara Hernandez is the brain behind A Girl Among Geeks a coding blog born from stubborn bugs, midnight learning, and a refusal to quit. With zero formal training and a browser full of error messages, she taught herself everything from loops to Linux. Her mission? Make tech less intimidating, one real answer at a time.

Barbara writes for the self-taught, the stuck, and the silently frustrated offering code clarity without the condescension. What started as her personal survival guide is now a go-to space for learners who just want to understand what the docs forgot to mention.