CentOs 7 Python Issue “-bash: python: command not found”

centospathpythonpython3

I asked this at stackoverflow, but just realized it might be best here. If I need to delete it over there or should not have posted here, please let me know. I am still new to this site. Thanks in advance!

I'm using centos 7 and was trying to install python 3.4 alongside python 2.6 (2.7?) the default install. I was attempting to change my bashrc file with an alias to make python 3.4 the default from the shell. It did not work, and I commented out the script, resourced bashrc, and now the system acts as if it can no longer find python, default or otherwise.

Just typing "python" returns:

-bash: python: command not found 

which python gives:

/usr/bin/which: no python in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/myusername/.local/bin:/home/myusername/bin) 

However there is a python install in both /usr/bin and /usr/sbin.

alternatives --list | grep -i python yields:

    python  auto  /usr/bin/python3.4

-v python returns nothing.

type -a python gives:

 -bash: type: python: not found

declare -p PATH outputs

declare -x PATH="/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/myusername/.local/‌​bin:/home/myusername/bin"

I am not entirely sure where to go from here, and any help would be much appreciated.

I do seem to have /usr/bin/python:

$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 24 Jun 25 15:39 /usr/bin/python -> /etc/alternatives/python 

but:

$ ls -l $(readlink -f /usr/bin/python) gives:

ls: cannot access /usr/bin/python3.4: No such file or directory

I do not know if this is relevant, but /etc/alternatives/python was pink looking in the terminal.

Edit 2:

ls -l /usr/local/bin/ prints -rwxr-xr-x 1 root root 101 Sep 4 2014 2to3-3.4
-rwxr-xr-x 1 root root 241 Sep 4 2014 easy_install-3.4
-rwxr-xr-x 1 root root 99 Sep 4 2014 idle3.4
-rwxr-xr-x 1 root root 213 Sep 4 2014 pip3.4
-rwxr-xr-x 1 root root 84 Sep 4 2014 pydoc3.4
-rwxr-xr-x 2 root root 17544 Sep 4 2014 python3.4
-rwxr-xr-x 2 root root 17544 Sep 4 2014 python3.4m
-rwxr-xr-x 1 root root 3066 Sep 4 2014 python3.4m-config
-rwxr-xr-x 1 root root 236 Sep 4 2014 pyvenv-3.4

So perhaps a linking error still?

Edit 3:

This is the series of commands which I used to install python 3.

yum install scl-utils
sudo yum install scl-utils
sudo wget https://www.softwarecollections.org/en/scls/rhscl/python33/epel-7-x86_64/download/rhscl-python33-epel-7-x86_64.noarch.rpm
sudo yum install rhscl-python33-*.noarch.rpm

Best Answer

It looks like you've lost your python installation. You have a link at /usr/bin/python which is pointing to /etc/alternatives/python. However, that itself is a link that is pointing to /usr/bin/python3.4 a file which apparently doesn't exist:

ls: cannot access /usr/bin/python3.4: No such file or directory

So, it looks like you simply haven't installed python3.4. I suggest you ask a new question, explaining exactly how you installed it.

Related Question