我有一个相当长的设置,然后最后三个问题。 在OS X上,System Python框架包含三个可执行文件(让我给它们简称):
> F=/System/Library/Frameworks/Python.framework/Versions/2.6
> A=$F/bin/python2.6
> B=$F/Resources/Python.app/Contents/MacOS/Python
> C=$F/Python
$ A和$ B显然太小而不能成为Python本身。
> ls -s $A; ls -s $B; ls -s $C
16 /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
16 /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
3152 /System/Library/Frameworks/Python.framework/Versions/2.6/Python
> $A
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
> $B
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
> $C
-bash: /System/Library/Frameworks/Python.framework/Versions/2.6/Python: cannot execute binary file
尽管尺寸相同且效果明显,但前两个是不同的,例如:
> cmp -lc $A $B
另外,在/ usr / bin中,python2.6是$ C的符号链接,但也有:
> D=/usr/bin/python
> ls -s $D
48 /usr/bin/python
我想弄清楚这些是如何连接的;命令which
无效。
> export DYLD_PRINT_LIBRARIES=1
> $A
..
dyld: loaded: /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
dyld: loaded: /System/Library/Frameworks/Python.framework/Versions/2.6/Python
摘要:$ A加载$ B后跟$ C; $ B加载$ C; $ D加载$ B后跟$ C
所以我的问题是:
答案 0 :(得分:3)
OS X 10.6中Apple提供的Pythons是使用标准的Python 框架构建选项构建和安装的,并进行了一些自定义调整。它不在Apple的文档中,因为具体的布局不是Apple的发明;多年来,Python项目使用其他OS X框架布局作为起点进化而来。如果您使用其中一个python.org安装程序在OS X上安装Python版本,例如来自here,您将看到相同的模式,框架以/Library/Frameworks/
而不是{{1}为根。 }。因此,如果您真的很好奇,可以下载源代码并查看/System/Library/Frameworks
脚本和configure
模板。不过,这可能是重读。 Apple还提供here用于在每个OS X版本中构建开源组件(包括Python)的源以及自定义补丁,因此,理论上,您可以准确了解Apple如何构建它所发布的内容。
那就是说,在Python 2.6中解决你的问题:
Makefile
是pythonw包装器,可确保OS X将Python识别为GUI应用程序(请参阅$A
here的来源)。请注意,已定制Apple版本的pythonw以添加首选执行模式(请参阅Apple的pythonw.c
)。在较新版本的Python(2.7和3.2)的上游源中提供了一种稍微不同的方法。
man 1 python
是Python解释器的实际可执行文件。它是pythonw可执行文件$B
exec
的内容。$A
。您应该能够通过实际运行Python并查看sys.executable
的值来轻松验证,但Apple提供的Python 2.6存在错误(可能是由于上面提到的附加功能)导致错误的值被分配给它。 python.org Python 2.6.6显示了正确的值:
$ cd /Library/Frameworks/Python.framework/Versions/2.6
$ ./bin/python2.6 -c 'import sys;print(sys.executable)'
/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python`
$C
是包含所有解释器可加载模块的共享库。您可以在otool
上使用$B
来查看:
$ cd /System/Library/Frameworks/Python.framework/Versions/2.6
$ cd Resources/Python.app/Contents/MacOS/
$ otool -L ./Python
Python:
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (compatibility version 2.6.0, current version 2.6.1)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
答案 1 :(得分:2)
要使用的工具是ls和file。
ls -l将给出符号链接的内容。符号链接的大小是它指向的路径中的字符数。
文件x将给出文件的类型
e.g。
file /System/Library/Frameworks/Python.framework/Versions/2.6/Python
/System/Library/Frameworks/Python.framework/Versions/2.6/Python: Mach-O universal binary with 3 architectures
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (for architecture i386): Mach-O dynamically linked shared library i386
/System/Library/Frameworks/Python.framework/Versions/2.6/Python (for architecture ppc7400): Mach-O dynamically linked shared library ppc
OSX框架在Apple developer docs
中描述/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python and /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6是实际的python解释器,我认为它们是同一个二进制文件的硬链接。
/ usr / bin / python是路径上的python - 我认为它很难链接到/ usr / bin / pythonw。这些是在/System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6中调用exec到真正的python解释器的包装器,请参阅python bug tracker
/System/Library/Frameworks/Python.framework/Versions/Current是使用标准OSX Framework版本控制的System / Library / Frameworks / Python.framework / Versions / 2.6的符号链接
/System/Library/Frameworks/Python.framework/Versions/2.6/Python是完成所有工作的共享库 - 设置为库,以便您可以使用其他语言编写可以嵌入python解释器的程序。
有关其他详细信息,请查看Python docs,但我怀疑您必须搜索apple python mailing list