未加星标

Linux / Unix: “-bash: python: command not found” error and solution

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二03 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏

Linux / Unix: “-bash: python: command not found” error and solution

I am a new user and trying to run python program. I have a cloud based VM/VPS and when I type python mycode.py at the terminal of my server, I get the following error:

-bash: python: command not found

How do I solve this problem?

This error means Python is either not installed or your installation damaged. Here is how you can solve this problem.

Check for python path Type any one of the following commands to see if python binary exists on a linux or Unix-like system: type -a python

OR

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

OR

which python

Sample outputs:


Linux / Unix: “-bash: python: command not found” error and solution

Fig.01: Python command not found

It seems that Python is missing for an unknown reason or was not installed by your cloud provider to save the disk space. So install it as per your Linux distro or Unix variant:

Ubuntu/Debian/Mint Linux install Python

Type the followingapt-get command orapt command

$ sudo apt-get install python

Or install python version 3:

$ sudo apt-get install python3 Oracle/RHEL (Red Hat)/CentOS Linux install Python

Type the followingyum command:

$ sudo yum install python Fedora Linux install Python

Type the following dnf command to add the Python v2.x:

$ sudo dnf install python

OR to add the Python v3.x:

$ sudo dnf install python3 Arch Linux install Python

Type the following pacman command to add the Python v2.x:

$ sudo pacman -S python2

OR add the Python v3.x:

$ sudo pacman -S python3 Suse/OpenSUSE Linux install Python

Type the following zypper command to add the Python v2.x:

$ sudo zypper install python

OR add the Python v3.x:

$ sudo zypper install 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

Sample outputs:

quirks-2.241 signed on 2016-07-26T16:56:10Z Ambiguous: choose package for python a 0: 1: python-2.7.12 2: python-3.4.5 3: python-3.5.2 Your choice:

MacOS X Unix install Python3

Type the following command:

$ brew install python3 Verify Python installation

Type the following commands:

$ type -a python $ which python $ ls -l /usr/bin/python $ ls -l /usr/bin/python*

Sample outputs:


Linux / Unix: “-bash: python: command not found” error and solution

Fig.02: Python installed on my OpenSUSE Linux box

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

Share this tutorial on:

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: LinuxPythonUbuntuDebianMacOSSUVPS
分页:12
转载请注明
本文标题:Linux / Unix: “-bash: python: command not found” error and solution
本站链接:http://www.codesec.net/view/522962.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(30)