Command
-bash:python:在centos 6上安裝python3後找不到命令
當我完成安裝python3時,我可以使用python2和python3命令,但是當我嘗試python時,它說找不到命令,這是一些輸出
[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]#
當我嘗試 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]#
當我在 /usr/bin 中嘗試 ls -ls 時,輸出 /usr/python/bin/python3 正在閃爍
[root@localhost bin]# ls -l 0 lrwxrwxrwx. 1 root root 23 Nov 13 01:05 python -> /usr/python/bin/python3
迴聲 $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
您將符號連結指向的位置
/usr/python/bin/python3
不正確。您的機器中似乎不存在該路徑。您可以在
/usr/local/python/bin/python3.6
.您可以在
/usr/bin/python2.7
.請注意,Python 社區建議不要將
python
名稱指向 Python 3。請參閱PEP-394 的這一部分,其中指出:如果
python
安裝了該命令,它應該呼叫與該命令相同版本的 Pythonpython2
。這不僅是一個建議,而且在許多 Linux 發行版中,將
python
符號連結移動到指向 Python 3 會破壞許多期望它指向 Python 2 的發行版包。我的建議是讓您恢復
python
符號連結以指向您的發行版提供的 Python 2,並創建一個單獨的python3
符號連結,您可以使用它來呼叫已安裝的 Python 3。您可以通過以下命令以 root 身份執行此操作(
sudo
例如,使用 ):ln -snf python2.7 /usr/bin/python ln -s ../local/python/bin/python3.6 /usr/bin/python3