linux查看python环境_运维笔记linux环境提示python: command not found hello

场景描述:

新部署的容器环境,终端执行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

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/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值