Making python3 point to python and pip3 to point to pip


I want to install python3 as python on my machine and I want pip3 to point to pip, as I don’t have any Python2 versions in my machine, will making this change affect any test behavior or break any python3 usage? If it does not, which files should I modify for the same.


You have not provided enough information for people to help you.
What OS are you using?

If its a linux distribution then you should be able to install an support package to set what python invokes.

Yes, I would like to do it in a linux distribution.

I would like to make this change in python source code itself while building it, such that both python3 and python point to Python3 . is there any way to do so?

This is not enough information for an exact answer. Which distribution is it? Also, what versions of Python are on the system; which one came with Linux; and which one should the python3 command use?

As an aside: normally, if there is any 3.x Python on the machine to begin with, python3 should have already been configured to use one of those. The occasionally tricky part is choosing whether python should run a 2.x or a 3.x installation; but since we are now over three years past the 2.x EOL, this is becoming a rarer concern.

Aside from not being possible*, this doesn’t make sense. The Python program isn’t responsible for its own command - neither is anything else you install. The shell takes the command that you type in, and tries to use it to look up a program, by checking paths in the PATH environment variable. It is definitely possible to make python and python3 do the same thing, but it has nothing to do with the underlying Python executable. Instead, typically one of those names will be symlinked to the other. (Other approaches that could theoretically work: making a shell alias; making some kind of wrapper executable that launches the other one.) In any event, this is OS-level functionality, not something that Python itself does.

* Pedantically: when Python is compiled, the makefile can specify rules that set up a symlink or whatever. So that is part of the process of building, but not part of the “source code” by a normal understanding.

1 Like

If you are using python from your distro then you can use the distro mechanism to set python to be a specific version of python. If you can tell us if it is a debian, fedora/rhel etc distro we can offer details.

If you are building installing python yourself then all you have to do is add a symlink,
assuming you are installing into /usr/local for your builds of python. You do not need to
change the python build at all.

If you are packaging this for others to use then you would add that symlink as part of
code that is specific it the package, .deb, .rpm etc.

ln -sf /usr/local/bin/python3 /usr/local/bin/python
1 Like

Thank you Barry, I am building an installing python on my own so, I have followed the symbolic link approach for now. I quoted the question wrongly earlier, I wasn’t looking to make this change in python source, I was trying to make it in some configuration related file or Makefile.

Thank you Karl, I had framed the question wrongly, I meant to make this change in config file or makefile which as you mentioned is part of build, thank you for pointing this out.

It will probably be easier to do this by just making a symlink (etc.) directly, or by using an installable package provided by your Linux vendor (which will basically just do that when you install it). Even if you compile Python multiple times, probably it will be in the same place each time, so any old symlink will still work.

1 Like