【问题标题】:How to check all versions of python installed on osx and centos如何检查安装在 osx 和 centos 上的所有 python 版本
【发布时间】:2015-08-08 12:10:06
【问题描述】:

今天刚开始搭建centos服务器,发现centos上python的默认版本设置为2.6.6。我想改用 python 2.7。我搜索了一下,发现 2.6.6 被 YUM 等系统工具使用,所以我不应该篡改它。然后我在我的 Mac 上打开一个终端,发现我安装了 python 2.6.8 和 2.7.5 和 3.3.3。对不起,故事很长。总之我只是想知道如何查找所有安装在centos上的python版本,所以我不会不小心安装两次。

【问题讨论】:

标签: python linux macos centos version


【解决方案1】:

我会添加到@nurealam siddiq 答案,

python --version // it shows your default Python installed version.

python2 --version // to check which version of python2 is installed 

python3 --version //to check which version of python3 is installed 

python3.X --version // to further check which python3.X is installed

【讨论】:

    【解决方案2】:

    这是一种更简洁的显示方式(技术上没有符号链接)。这包括 python2 和 python3 安装:

    ls -1 /usr/bin/python* | grep '.*[2-3]\(.[0-9]\+\)\?$'
    

    grep 过滤 ls 的输出,该输出在末尾具有该数字模式 ($)。

    或者使用find:

    find /usr/bin/python* ! -type l
    

    其中显示了符号链接类型 (-type l) 的所有不同 (!)。

    【讨论】:

      【解决方案3】:
      ls -l /usr/bin/python* & ls -l /usr/local/bin/python*
      

      【讨论】:

        【解决方案4】:

        筛选此脚本的输出。

        sudo find / -name 'python*' -type f  -exec du -h {}  + | sort -r -h ~/Documents/python_locations.txt
        

        【讨论】:

          【解决方案5】:
          compgen -c python | grep -P '^python\d'
          

          这也列出了一些其他python的东西,但是嘿,你可以识别其中所有的python版本。

          【讨论】:

            【解决方案6】:

            命令:python --version && python3 --version

            输出:

            Python 2.7.10
            Python 3.7.1

            别名命令:pyver

            输出:

            Python 2.7.10
            Python 3.7.1

            您可以在 .bashrc 文件中创建类似“pyver”的别名,或者使用 AText 等文本加速器。

            【讨论】:

            • 这假设用户知道他们有 python2.x 和 python3.x。如果他们有 anaconda 并想查看这些版本怎么办?这还不够笼统,很有帮助。
            【解决方案7】:

            这取决于您的默认 python 设置版本。可以按Python版本查询:

            python3 --version //to check which version of python3 is installed on your computer
            python2 --version // to check which version of python2 is installed on your computer
            python --version // it shows your default Python installed version.
            

            【讨论】:

              【解决方案8】:

              我们可以直接使用它来查看当前用户和root安装的所有python,方法如下: whereis python

              【讨论】:

                【解决方案9】:

                通过发出命令找出安装了哪个版本的 Python 蟒蛇--版本: $蟒蛇--版本 Python 2.7.10

                如果您看到这样的内容,Python 2.7 是您的默认版本。您还可以查看是否安装了 Python 3:

                $ python3 --version
                Python 3.7.2
                

                如果你也想知道它的安装路径,可以用python和python3发出命令“which”:

                $ which python
                /usr/bin/python
                
                $ which python3
                /usr/local/bin/python3
                

                【讨论】:

                  【解决方案10】:

                  执行下一条命令更简单:

                  ls -ls /usr/bin/python*
                  

                  输出如下所示:

                  /usr/bin/python           /usr/bin/python2.7        /usr/bin/pythonw
                  /usr/bin/python-config    /usr/bin/python2.7-config /usr/bin/pythonw2.7
                  

                  【讨论】:

                  • 这个答案不是很具体,请编辑它以澄清意图。
                  • 这个是为我做的。 which python etc 只给我当前使用的版本,而不是其他安装的版本。
                  • 小心,有些也可以安装在 usr/local 中。所以也运行这个。 ls -ls /usr/local/bin/python*
                  • 对于 OSX 用户,python2.7 预安装在 /usr/bin/ 中,但用户下载和安装的任何 python 版本都可能在 /usr/local/bin/ 中(参见 OutOnAWeekend 的评论)。
                  • 这也会遗漏 anaconda 中的任何内容。对我来说,听起来最初的问题是如何为整个系统执行此操作,而不仅仅是在 usr/bin 中
                  【解决方案11】:

                  使用,

                  yum list installed
                  命令来查找您安装的软件包。

                  【讨论】:

                  • 它没有给出系统中安装的python的列表。所以想要python版本,而不是包列表。根据我的说法,@gabriel 的答案很好。您也可以使用 "whereis python" 。它还给出了我的 centos 和 Mac 系统上的 python 列表。
                  • 在这种情况下你可以做yum list installed | grep python
                  • 兄弟已经完成了。现在它显示列表 python 包而不是 python 版本列表
                  【解决方案12】:

                  正如有人在评论中提到的,如果 CentOS 支持,您可以使用which python。另一个可行的命令是whereis python。如果这些都不起作用,您可以启动 Python 解释器,它会显示版本,或者您可以在 /usr/bin 中查找 Python 文件(python、python3 等)。

                  【讨论】:

                    猜你喜欢
                    • 1970-01-01
                    • 2021-12-11
                    • 2013-12-02
                    • 2023-03-04
                    • 2016-10-12
                    • 2021-04-26
                    • 2014-10-15
                    • 1970-01-01
                    • 2018-06-28
                    相关资源
                    最近更新 更多