Create an Alias for Python

Create an Alias for Python

  1. Create an Alias for Python
  2. Change Python Version in VS Code
  3. Conclusion

Sometimes you have your favorite version of Python and don’t want to let go of it when a new version arrives. You might have old scripts that have failed to work on new versions of Python, or you have too many projects on the old version that moving them over to a new version is a marathon.

In situations like this, you decide to keep both versions of Python. In this article, we’ll learn how to create an alias where you have two Python versions.

Create an Alias for Python

You want to code in your terminal, and you want to be able to apply whichever version you want to your codes. How do we do that?

To begin, old versions of Python, like Python 2.7.10, can be called in the command prompt with "python" while the latest versions like Python 3.10.7 can be called in the command prompt with "py". Hence we can use "python" and "py" as aliases for each version.

Now, open the command prompt and type in python --version; it will bring up the old Python version. If you type in py --version, it prints out the new Python version.

Suppose we want to code with the older version inside the command prompt, type python and hit enter. After the >>, type in the codes and hit enter.

Use “python” to initiate older version in cmd

The same logic goes for when you want to use the newer one. Start by typing py inside the command prompt, press enter and type in your codes.

Use “py” to initiate newer version in cmd

Change Python Version in VS Code

If you’re wondering whether or not you could change Python versions in VS Code, you can change it, and it is pretty easy. Just look down at the bottom left of the VS Code, and you will see the python version VS Code is currently using.

Click on it, and a box opens at the top of VS Code that displays the Python versions you have installed. Please select one of your choices, wait for a few seconds for the changes to take effect, and it’s done.

Change Python Version in VS Code


When Python versions change, having new and old versions helps you track the changes in how you are to code, and you can choose to ignore the changes by using the old or adapting to the changes. Either way, this gives coders room to explore and see the best way to come up with writing codes.

Oluwafisayo Oluwatayo avatar Oluwafisayo Oluwatayo avatar

Fisayo is a tech expert and enthusiast who loves to solve problems, seek new challenges and aim to spread the knowledge of what she has learned across the globe.