【问题标题】:osx - What's the difference between /usr/bin/python and /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7?osx - /usr/bin/python 和 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 有什么区别?
【发布时间】:2018-02-12 05:51:41
【问题描述】:

我正在尝试清理我的系统 python 环境。我之前使用 Homebrew 安装了另一个 python2 而不是系统提供的一个,我已经卸载了这个。

我认为现在我的 mac 上应该只有一个 python2。但是,which python 给出了/usr/bin/python,我注意到/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python 中还有另一个。

/usr/bin/ls -l 的输出为

lrwxr-xr-x   1 root   wheel        74 Jul 22  2015 pydoc2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pydoc2.6
lrwxr-xr-x   1 root   wheel        74 Jul 22  2015 pydoc2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pydoc2.7
-rwxr-xr-x   2 root   wheel     58416 Jul 15  2015 python
-rwxr-xr-x   5 root   wheel       925 Sep 10  2014 python-config
lrwxr-xr-x   1 root   wheel        18 Apr  8  2016 python2 -> /usr/bin/python2.7
lrwxr-xr-x   1 root   wheel        75 Jul 22  2015 python2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
lrwxr-xr-x   1 root   wheel        82 Jul 22  2015 python2.6-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6-config
lrwxr-xr-x   1 root   wheel        75 Jul 22  2015 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x   1 root   wheel        82 Jul 22  2015 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
-rwxr-xr-x   2 root   wheel     58416 Jul 15  2015 pythonw
lrwxr-xr-x   1 root   wheel        76 Jul 22  2015 pythonw2.6 -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/pythonw2.6
lrwxr-xr-x   1 root   wheel        76 Jul 22  2015 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7

所以我认为这意味着/usr/bin/python 不是符号链接,它本身就是二进制文件。同时/usr/bin/python2.7/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 的符号链接。

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/

lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 2to3 -> 2to32.7
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 2to3-2 -> 2to3-2.7
-rwxr-xr-x  1 root  wheel    288 Sep 10  2014 2to3-2.7
lrwxr-xr-x  1 root  wheel      6 Jul 22  2015 2to32.7 -> 2to3-2
lrwxr-xr-x  1 root  wheel      5 Jul 22  2015 idle -> idle2
lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 idle2 -> idle2.7
-rwxr-xr-x  1 root  wheel    230 Sep 10  2014 idle2.7
lrwxr-xr-x  1 root  wheel      6 Jul 22  2015 pydoc -> pydoc2
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 pydoc2 -> pydoc2.7
-rwxr-xr-x  1 root  wheel    215 Sep 10  2014 pydoc2.7
lrwxr-xr-x  1 root  wheel      7 Jul 22  2015 python -> python2
lrwxr-xr-x  1 root  wheel     14 Jul 22  2015 python-config -> python2-config
lrwxr-xr-x  1 root  wheel      9 Jul 22  2015 python2 -> python2.7
lrwxr-xr-x  1 root  wheel     16 Jul 22  2015 python2-config -> python2.7-config
-rwxr-xr-x  1 root  wheel  34944 Jul 15  2015 python2.7
-rwxr-xr-x  1 root  wheel   1818 Jul 15  2015 python2.7-config
lrwxr-xr-x  1 root  wheel      8 Jul 22  2015 pythonw -> pythonw2
lrwxr-xr-x  1 root  wheel     10 Jul 22  2015 pythonw2 -> pythonw2.7
-rwxr-xr-x  1 root  wheel  34944 Jul 15  2015 pythonw2.7
lrwxr-xr-x  1 root  wheel      9 Jul 22  2015 smtpd.py -> smtpd2.py
-rwxr-xr-x  1 root  wheel  18681 Sep 10  2014 smtpd2.7.py
lrwxr-xr-x  1 root  wheel     11 Jul 22  2015 smtpd2.py -> smtpd2.7.py

但是,/usr/bin/python/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 似乎是相同的二进制文件,因为它们都给出了

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

当我运行它们时。

我很困惑这两个二进制文件是否表示相同的 python 解释器?但是为什么它们是两个独立的二进制文件呢?

【问题讨论】:

  • /usr/bin 条目 lrwxr-xr-x 1 root wheel 75 Jul 22 2015 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7/System/... 下的符号链接 - 它们是相同的。
  • @metatoaster 但是/usr/bin/python 不是/usr/bin/python2.7 的符号链接?

标签: python macos python-2.7


【解决方案1】:

这是 MacOSX 版本控制系统的一部分。您的实际 Python 可执行文件位于 /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

/usr/bin/python 是一个包装器,它根据com.apple.versioner.python.plist 属性列表文件和VERSIONER_PYTHON_VERSION 环境变量等中指定的版本选择要使用的python 版本。

Perl 以同样的方式工作。它旨在允许用户在操作系统附带的 python 和 perl 版本之间进行选择,尽管从 macOS 版本 10.14.2 (mojave) 开始,每个版本只安装一个。

如果您确实安装了多个版本的 Python,您可以使用以下命令更改默认版本:

defaults write com.apple.versioner.python Version -string 2.7.10

export VERSIONER_PYTHON_VERSION=2.7.10

这只是一个示例,假设安装的是 2.7.10 版本。

以上内容仅适用于 Apple 操作系统中包含的程序,不适用于通过 Homebrew 或 MacPorts 安装、自行下载或编译的版本。

来源:http://krypted.com/mac-os-x/perl-control/https://gist.github.com/crankycoder/1389144

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 2016-05-08
    • 2015-05-12
    • 2020-07-25
    • 2021-09-18
    • 1970-01-01
    • 2018-05-12
    相关资源
    最近更新 更多