Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From the terminal verify if python 3 is installed

Tags:

I am writing a shell script, and before the script runs I want to verify that the user has Python 3 installed. Does anyone know or have any ideas of how I could check that, and the output be a boolean value?

like image 544
alexr17 Avatar asked Jul 20 '16 15:07

alexr17


1 Answers

Interactive shell

Simply run python3 --version. You should get some output like Python 3.8.1 if Python 3 is installed.

Shell script

You can use the command or type builtins:

command -v python3 >/dev/null 2>&1 && echo Python 3 is installed  # POSIX-compliant type -P python3 >/dev/null 2>&1 && echo Python 3 is installed     # Bash only 

Using which is not recommended as it requires launching an external process and might give you incorrect output in some cases.

like image 110
Eugene Yarmash Avatar answered Sep 28 '22 03:09

Eugene Yarmash