如何在 OSX Lion 下独立于/System/Library/Frameworks 安装 Python 2.7.x? [英] How to install Python 2.7.x independently of /System/Library/Frameworks under OSX Lion?

查看:62
本文介绍了如何在 OSX Lion 下独立于/System/Library/Frameworks 安装 Python 2.7.x?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法构建和安装 Python 2.7.x,使其对/System/Library/Frameworks 下的任何内容没有任何直接依赖性?(IOW,即使在 sudo chmod 000/System/Library/Frameworks 之后,这样的 Python 也应该保持功能.)

Is there a way to build and install Python 2.7.x so that it has no direct dependency whatsoever on anything under /System/Library/Frameworks? (IOW, such Python should remain functional even after sudo chmod 000 /System/Library/Frameworks.)

我认为在运行 ./configure 时省略 --enable-framework 标志就足够了,但我错了:如果我这样做了,结果 Python 仍然对/System/Library/Frameworks 下的框架有很多依赖,当然包括/System/Library/Frameworks/Python.framework.(IOW,人们不得不怀疑在安装和不选择--enable-framework 的情况下是否有任何区别.)

I thought it would be enough to omit the --enable-framework flag at the time of running ./configure, but I was wrong: if I do this the resulting Python still has plenty of dependencies to frameworks under /System/Library/Frameworks, including, of course, /System/Library/Frameworks/Python.framework. (IOW, one has to wonder if there's any difference between installing with and without selecting --enable-framework.)

推荐答案

是的,--enable-framework 在构建和安装 Python 时会有所不同.如果没有 --enable-framework,Python 构建为传统的unix 风格"构建,默认情况下安装到 /usr/local/ 但可以通过 /usr/local/ 进行更改code>--prefix= 选项到 ./configure.--enable-framework 构建一个 Python,默认情况下,该 Python 安装在 /Library/Frameworks 中,尽管可以通过指定另一个路径来更改 --启用框架.但是任何 Python 构建都将依赖于操作系统提供的其他库和框架.这是正常的.你为什么要担心?

Yes, --enable-framework makes a difference when building and installing Python. Without --enable-framework, Python is built as a conventional "unix-style" build by default installed to /usr/local/ but that can be changed with the --prefix= option to ./configure. --enable-framework builds a Python that, by default, is installed into /Library/Frameworks, although that can be changed by specifying another path to --enable-framework. But any Python build will be dependent on other libraries and frameworks provided by the operating system. This is normal. Why are you concerned about it?

更新:很容易避免使用 Apple 提供的系统 Python,例如那些在/usr/bin 中并且其共享组件在/System/Library/Frameworks/Python.frameworks 中的那些,只需安装另一个 Python 2.7 而不是使用/usr/bin/python2.7.但这并不意味着您应该或可以避免使用其他系统框架.

Update: It's easy to avoid using the Apple-supplied system Pythons, e.g. those which are in /usr/bin and whose shared components are in /System/Library/Frameworks/Python.frameworks, just by installing another Python 2.7 and not using /usr/bin/python2.7. But that doesn't mean you should or can avoid using other system frameworks.

也就是说,在 OS X 10.6 到 10.8 中,有一个已知有问题的 Apple 提供的框架被 Python 使用:即 Tk 8.5,被包括 IDLE 在内的 Python Tkinter 应用程序使用.幸运的是,解决这个问题很容易.与 Python 一样,您可以将更新的第三方版本的 Tcl 8.5 和 Tk 8.5 框架安装到 /Library/Frameworks 中,并且某些 Python 发行版(如来自 python.org 的二进制安装程序)将使用它们.如果您可以使用 ActiveTcl 发行版,我们推荐它.参见 http://www.python.org/download/mac/tcltk/更多信息.

That said, there is one known problematic Apple-supplied framework in OS X 10.6 through 10.8 that is used by Python: that is Tk 8.5, used by Python Tkinter applications including IDLE. Fortunately, it is pretty easy to work around that. Like Python, you can install a newer, third-party version of the Tcl 8.5 and Tk 8.5 frameworks into /Library/Frameworks and some Python distributions, like the binary installers from python.org, will use them. We recommend the ActiveTcl distribution if you are able to use it. See http://www.python.org/download/mac/tcltk/ for more information.

另外,请注意您需要安装单独版本的 Distribute(或 setuptools)、pip(如果您使用它),和/或 virtualenv 用于每个 Python 实例.不要陷入在 /usr/bin/ 中使用 Apple 提供的用于系统 Python 的 easy_install 命令的陷阱.

Also, be aware that you need to install separate versions of Distribute (or setuptools), pip (if you use it), and/or virtualenv for each instance of Python you have. Don't fall into the trap of using the Apple-supplied easy_install commands in /usr/bin/ which are for the system Pythons.

进一步更新:进一步完善

Further update: With the further refinement

避免使用/S/L/F/Python.framework 下的所有内容".我已经尝试过了类似于您所描述的,但结果安装仍然取决于/S/L/F/Python.framework 下的东西

avoid all the stuff under /S/L/F/Python.framework". I already tried something like what you describe, but the resulting installation still depends on stuff under /S/L/F/Python.framework

我所能做的就是重申构建您自己的 Python,无论是unix"构建、共享"构建还是框架"构建,生成的 Python 应该完全独立于 /系统/库/框架/Python.framework.如果没有,则说明构建或您执行 Python 的方式出了问题.需要更多细节来确定出了什么问题,至少是这样的:

all I can do is reiterate that building your own Python, be it a "unix" build, a "shared" build, or a "framework" build, the resultant Python should be totally independent of anything in /System/Library/Frameworks/Python.framework. If not, something went wrong in the build or in how you are executing Python. More details would be needed to determine what is going wrong, at a minimum something like:

/path/to/your/python -c "import sys, pprint; print(sys.version); print(sys.executable); pprint.pprint(sys.path)"

如果您构建了 Python,我们需要查看完整的 configuremake 命令.但这会导致本地化调试并不适合 StackOverflow.

If you built the Python, we'd need to see the complete configure and make commands. But that would be getting into localized debugging not really appropriate for StackOverflow.

最后(!)更新:在框架构建中,--enable-framework=/path/to 选项 configure 使用该前缀"作为安装如果您坚持使用以 Library/Frameworks 结尾的路径,则框架和两个辅助目录的前缀"位置.所以,如果你使用:

Last (!) update: In a framework build, the --enable-framework=/path/to option to configure uses that "prefix" as the install "prefix" location for the framework and two auxiliary directories if you stick to using paths that end in Library/Frameworks. So, if you used:

./configure --enable-framework=/baz/quux/Library/Frameworks && make && make install

它应该导致:

/baz
    quux
        Applications
            Python 2.7
                Build Applet.app
                IDLE.app
                ...
        Library
            Frameworks
                Python
                    Version
                        2.7
                            Headers/
                            Python
                            ...
                            Resources/
                            bin
                                ...
                                2to3
                                idle2.7
                                ...
                                python
                                python2
                                python2.7
                                ...
                            include/
                            lib/
                            share/
        bin
            2to3 -> ...bin/2to3
            ...
            idle2.7 -> ...bin/idle2.7
            ...
            python -> ...bin/python
            ...

顶级 bin 目录有点残留,实际上只是混淆了问题.它包含指向框架 bin 目录中的可执行文件的符号链接.它是通过默认框架构建安装在 /usr/local/bin 中的.使用它的一个问题是,默认情况下,Distutils 安装的脚本将安装到框架 bin 目录中,并且在顶级目录中不会有它们的别名.这就是为什么建议您将框架 bin 目录放在 shell PATH 的头部,而忽略顶层 bin.

The top-level bin directory is somewhat vestigial and really just confuses matters. It contains symlinks to the executables in the framework bin directory. It's what gets installed in /usr/local/bin by a default framework build. One problem with using it is that Distutils-installed scripts will, by default, get installed to the framework bin directory and there won't be an alias for them in the top-level directory. That's why it is recommended that you put the framework bin directory at the head of your shell PATH and just ignore the top-level bin.

如果将--prefix=/foo/bar添加到前面的configure中,它将使用前缀路径作为残留顶级bin目录的根.在上面的示例中,顶级 bin 目录将安装在:

If --prefix=/foo/bar is added to the previous configure, it will use the prefix path as the root for the vestigial top-level bin directory. In the above example, that top-level bin directory would be installed instead at:

/foo
    bar
        bin
            2to3 -> ...bin/2to3
            ...
            idle2.7 -> ...bin/idle2.7
            ...
            python -> ...bin/python
            ...

否则,它应该没有效果.

Otherwise, it should have no effect.

这篇关于如何在 OSX Lion 下独立于/System/Library/Frameworks 安装 Python 2.7.x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆