運維筆記--linux環境提示python: command not found


場景描述:

新部署的容器環境,終端執行python命令,提示沒有該命令。

從報錯異常可以看出,可能是python環境未安裝。

分析思路:

檢查python路徑:

方式一:

type -a python

方式二:

ls -l /usr/bin/python
ls -l /usr/bin/python*

方式三:

which python

如果輸出空或者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
或者:
$ 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/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM