osx - / usr / bin / python和/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7之间有什么区别?

时间:2018-02-12 05:51:41

标签: python macos python-2.7

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

我认为我的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解释器?但为什么它们是两个独立的二进制文件?

1 个答案:

答案 0 :(得分:0)

这是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