場景描述:python
新部署的容器環境,終端執行python命令,提示沒有該命令。bash
從報錯異常能夠看出,多是python環境未安裝。spa
分析思路:code
檢查python路徑:ci
方式一:type -a python部署
方式二:get
ls -l /usr/bin/python
ls -l /usr/bin/python*it
方式三:io
which pythontable
若是輸出空或者no such file or directory, 則說明未安裝。
處理過程:
不一樣Linux系統版本安裝方式不一樣!
Ubuntu/Debian/Mint Linux install Python
安裝python2
$ sudo apt-get install python
安裝python3
$ sudo apt-get install python3
Oracle/RHEL (Red Hat)/CentOS Linux install Python
$ sudo yum install python
Fedora Linux install Python
python2: $ sudo dnf install python
python3: $ sudo dnf install python3
MacOS X Unix install Python3
Type the following command:$ brew install python3
Arch Linux install Python
python2: $ sudo pacman -S python2
python3:$ sudo pacman -S python3
FreeBSD Unix install Python
Type the following pkg command to add the Python v2.x:# pkg install python2
OR To install the Python v2.x port:# cd /usr/ports/lang/python2/ && make install clean
To add the Python v3.x package:# pkg install python3
OR To install the Python v3.x port:# cd /usr/ports/lang/python3/ && make install clean
OpenBSD Unix install Python
Type the following pkg_add command to add the Python v2.x or 3.x:# pkg_add python
OR$ doas pkg_add python
若是須要建立軟連接:
A note about broken symlink
Sometimes a soft link to Pythons’s executables is broken for some reason. For example, /usr/bin/python3.4 is real executables. You can point /usr/bin/python to /usr/bin/python3.4 for Python version 3.4 using the ln command:$ sudo ln -s /usr/bin/python3.4 /usr/bin/python
Now you can run program:$ python mycode.py
參考:https://www.cyberciti.biz/faq/bash-python-command-not-found/