0

I'm working on Fedora 21 and, don't ask me why, but I have two versions of Python 2.x installed on it. I can tell that I have two different versions because when I call it from the terminal with "python", I get:

Python 2.7.9 (default, Feb 18 2017, 17:18:34)

[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

I'd like to add that the version that I call with "python" is "/usr/local/bin/python". On the other hand, when I call it with "/usr/bin/python", I get:

Python 2.7.8 (default, Sep 24 2015, 18:25:44)

[GCC 4.9.2 20150212 (Red Hat 4.9.2-6)] on linux2

Type "help", "copyright", "credits" or "license" for more information.

On top of that, they don't seem to have access to the same libraries/modules. For example, if I run a script using SciPy with "python" it raises an error, while that's not the case if I run it with "/usr/bin/python".

So, how do I get rid of the version running when I call it with "python" and keep the one that I call with "/usr/bin/python"? Moreover, I'd like to call the one that I'm curently calling with "/usr/bin/python" with a simple "python".

2 Answers 2

2

You could attempt to remove the one under /usr/local/bin/python by finding out what RPM installed it:

rpm -f /usr/local/bin/python

Once you have one version only it will be the one called.

Two other options are:
a) Modify your PATH variable so that /usr/bin comes before /usr/local/bin
b) Alias 'python' to '/usr/bin/python'

4
  • Thanks. I did "rpm -qf /usr/local/bin/python" and I got "file /usr/local/bin/python is not owned by any package". How should I proceed to uninstall it?
    – Pipicito
    Jun 10, 2017 at 16:50
  • 1
    I'm this case it could probably just be removed. However, /use/local is often where people install software and scripts manually. Someone may have put it there for a reason. Another option would be to simply rename this one to 'python279' (or anything other than 'python').
    – LJKims
    Jun 10, 2017 at 20:27
  • And what about the fact that "/usr/local/bin/python" is unable to see modules that "/usr/bin/python" can see? What is the explanation for that?
    – Pipicito
    Jun 10, 2017 at 20:58
  • 1
    Python uses a search path similar to the system shell. Most of it is built in to the python executable. You can view it interactively: # python, >>> import sys, >>> sys.path, See: docs.python.org/3/library/sys.html#sys.path
    – LJKims
    Jun 11, 2017 at 1:33
2

There's no real reason to delete one of the Pythons (other applications may depend on it).

To use /usr/bin/python by default, make sure that /usr/bin comes before /usr/local/bin in your $PATH.

You may investigate this with echo $PATH and it's possible to simply add /usr/bin to the front of that value with

PATH="/usr/bin:$PATH"

in your shell startup files. Having /usr/bin listed multiple times in $PATH is not an issue.

If you write Python scripts, just make sure that the shebang-line reads

#!/usr/bin/python

and that the script is executable. This will make it pick up the Python interpreter that you want.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .