9

when i finish install python3 , i can use python2, and python3 command ,but when i try python , it says command not found ,here is some output

[root@localhost bin]# python2
Python 2.7.5 (default, Apr 11 2018, 07:36:10) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
[root@localhost bin]# python3.6
Python 3.6.0 (default, Nov 13 2018, 00:07:36) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
[root@localhost bin]# python
-bash: python: command not found
[root@localhost bin]#

when i try whereis python

 [root@localhost bin]# whereis python
 python: /usr/bin/python2.7 /usr/bin/python /usr/bin/python.bak 
 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 
 /usr/local/python /usr/local/python/bin/python3.6m 
 /usr/local/python/bin/python3.6 /usr/local/python/bin/python3.6m-config 
/usr/local/python/bin/python3.6-config /usr/share/man/man1/python.1.gz
[root@localhost bin]#

when i try ls -ls in /usr/bin,in the output /usr/python/bin/python3 is flashing

[root@localhost bin]# ls -l
0 lrwxrwxrwx. 1 root root         23 Nov 13 01:05 python -> 
/usr/python/bin/python3

echo $PATH

[root@localhost /]# echo $PATH
/usr/local/python/bin/:/usr/local/python/bin/:/usr/local/sbin:
/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
ethan
  • 93

1 Answers1

10

The location you're pointing your symlink to, /usr/python/bin/python3, is incorrect. That path doesn't seem to exist in your machine.

You have Python 3 available at /usr/local/python/bin/python3.6.

You have Python 2 available at /usr/bin/python2.7.

Note that Python community recommends against making the python name point to Python 3. See this section of PEP-394, which states:

If the python command is installed, it should invoke the same version of Python as the python2 command.

Not only that's a recommendation, but in many Linux distributions, moving the python symlink to point to Python 3 will break many packages of the distribution that expect it to be pointing to Python 2.

My advice is for you to restore the python symlink to point to Python 2 shipped by your distro and create a separate python3 symlink you can use to invoke Python 3 you have installed.

Which you can do by the following commands as root (using sudo, for example):

ln -snf python2.7 /usr/bin/python
ln -s ../local/python/bin/python3.6 /usr/bin/python3
filbranden
  • 21,751
  • 4
  • 63
  • 86