运维笔记--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