如何检查系统是否安装了最新的Python版本(python3.10)?

huangapple go评论72阅读模式
英文:

How to check if system is installed with latest python version (python3.10)?

问题

I am using following shell command to find the latest python is installed

$ python3 -c 'import sys; print(sys.version_info)'
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)

But this command is returning the default python version (3.8) that was pointing to python3, instead of higher python version installed (3.10).

How to check if python3.10 version is installed in a host ?

英文:

I am using following shell command to find the latest python is installed

$ python3 -c 'import sys; print(sys.version_info)'
sys.version_info(major=3, minor=8, micro=10, releaselevel='final', serial=0)

But this command is returning the default python version (3.8) that was pointing to python3, instead of higher python version installed (3.10).

How to check if python3.10 version is installed in a host ?

答案1

得分: 0

你可以使用以下命令来查找已安装的所有Python版本(适用于具有默认路径安装Python的Red Hat和Debian衍生版本):

ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n

要找到最新的版本,可以使用以下命令:

ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n | tail -n 1

如果要检查特定版本是否已安装,可以使用以下命令,例如,检查是否安装了Python 3.10:

test $(ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n | tail -n 1) -eq 310 && echo "Python version 3.10 is installed in this host." || echo "A version of python different than 3.10 is installed."
英文:

You can find out all your versions installed with (works with Red Hat and Debian derivatives with default path installations of python)

ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n 

the latest with

ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n | tail -n 1

and to check for specific version

test $(ls /usr/bin/python* | grep -o '[0-9]\+\.[0-9]\+' | tr -d '.' | sort -n | tail -n 1) -eq 310 && echo "Python version 3.10 is installed in this host." || echo "A version of python different than 3.10 is installed."

答案2

得分: -1

To specify the use of version 3.10 you can use

py -3.10 -c 'import sys; print(sys.version_info[:])';
英文:

To specify the use of version 3.10 you can use

py -3.10 -c 'import sys; print(sys.version_info[:])'

答案3

得分: -1

compgen -c | grep -i python3.10 (或者 python 以查看所有版本)。

英文:

compgen -c | grep -i python3.10 (or python to see all versions).

huangapple
  • 本文由 发表于 2023年4月13日 23:34:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76007288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定