简体   繁体   English

在OS X 10.6上编译Python 2.5.5

[英]Compile Python 2.5.5 on OS X 10.6

I would like to install Python 2.5.5 to use with Google apps but have been having a very hard time tracking down instructions on how to do so. 我想安装Python 2.5.5以便与Google应用配合使用,但是一直很难找到有关如何执行操作的说明。 I am thinking the following might work but was wondering if anyone had successfully built it? 我认为以下内容可能有效,但想知道是否有人成功构建了它?

./configure --prefix=/usr/local/python2.5.5 MACOSX_DEPLOYMENT_TARGET=10.6 --enable-framework --with-universal-archs="64-bit" CFLAGS="-arch x86_64" LDFLAGS="-arch x86_64"

~: make -j6

~: sudo make install

Any help is appreciated! 任何帮助表示赞赏!

You should install it via MacPorts , which makes this a piece of cake. 您应该通过MacPorts安装它,这很容易。 After you have it installed... 安装后...

$ sudo port install python25

You should install it via Fink , which makes this a piece of cake. 您应该通过Fink安装它,这很容易。 After you have it installed... 安装后...

$ fink install python25

Fink has more packages than MacPorts. Fink的软件包多于MacPorts。

Assuming that you are running OS 10.6, At the terminal if you type 假设您正在运行OS 10.6,请在终端上键入

% python<tab>

The terminal should show you all the python* items on your PATH . 终端应显示PATH上的所有python*项目。 As suggested by @philipp , Python 2.5 and Python 2.6 are installed by default. 根据@philipp的建议,默认情况下会安装Python 2.5和Python 2.6。 You can see listed as: 您可以看到列为:

python2.5
python2.6

You will also see an entry which is just python . 您还将看到一个只是python的条目。 This is the one that is going to used by default when you invoke the command python at the command line. 这是在命令行中调用python命令时默认使用的代码。 To see the version of this default version either start it by typing python at the command line and note the text printed out at startup, or do a which python to see the absolute path for that executable. 要查看此默认版本的版本,请在命令行中键入python来启动它,并注意启动时打印出的文本,或者执行一个which python来查看该可执行文件的绝对路径。

The executables in the PATH on OS X are managed by links, so to see the actual location OS X上PATH的可执行文件由链接管理,因此可以查看实际位置

ls -lha `which python`
ls -lha `which python2.5`
ls -lha `which python2.6`

Note the backtics will cause the which command to run and insert the result into the ls command. 请注意,背景将导致运行which命令,并将结果插入ls命令。

Lastly, you can choose the version of Python which is the default by using the python_select command. 最后,您可以使用python_select命令选择Python的默认版本。 I don't have a lot of experience with this, as I usually manage my access to Python via my own soft links or shell aliases. 我没有太多的经验,因为我通常通过自己的软链接或外壳别名来管理对Python的访问。

That all being said, if you are going to be installing a lot of packages for development purposes give the advice of @Dave Pirotte a try. 话虽如此,如果您将要安装很多用于开发目的的软件包,请尝试@Dave Pirotte的建议。 By using MacPorts , or fink , you will get a new installation of Python (and whatever further packages you need) outside of the system Python installation. 通过使用MacPortsfink ,您将在系统Python安装之外获得Python的新安装(以及所需的任何其他软件包)。 This can be handy if you need to make a lot of modifications and if you're going to hard on the health of your Python installation it is easier to whipe the slate clean and start over if you don't mess with the default system Python. 如果您需要进行大量修改,并且如果您要对Python安装的运行状况有所帮助,那么这会很方便,如果您不使用默认的系统Python,则更容易将板岩清理干净并重新开始。

Python 2.5 does not build correctly out of the box on Mac OS X 10.6. 在Mac OS X 10.6上,Python 2.5无法直接正确地构建。 (It does build OK as is on 10.5 or 10.4, though.) There is at least one configure fix that needs to be backported from later Pythons. (尽管它确实可以在10.5或10.4上一样构建OK。)至少有一个配置修复程序需要从更高版本的Python中反向移植。 And you need to use gcc-4.0, not -4.2. 而且您需要使用gcc-4.0,而不是-4.2。 Once you have extracted the source: 提取源代码后:

cd ./Python-2.5.5/
cat >patch-configure-for-10-6.patch <<EOF
--- configure.O 2008-12-13 06:13:52.000000000 -0800
+++ configure   2010-09-29 10:16:05.000000000 -0700
@@ -2039,7 +2039,11 @@
   # disables platform specific features beyond repair.
   # On Mac OS X 10.3, defining _POSIX_C_SOURCE or _XOPEN_SOURCE
   # has no effect, don't bother defining them
-  FreeBSD/4.* | Darwin/[6789].*)
+  FreeBSD/4.*)
+    define_xopen_source=no;;
+  Darwin/[6789].*)
+    define_xopen_source=no;;
+  Darwin/1[0-9].*)
     define_xopen_source=no;;
   # On AIX 4 and 5.1, mbstate_t is defined only when _XOPEN_SOURCE == 500 but
   # used in wcsnrtombs() and mbsnrtowcs() even if _XOPEN_SOURCE is not defined
EOF
patch < patch-configure-for-10-6.patch
export CC=/usr/bin/gcc-4.0
./configure --prefix=/usr/local --enable-framework MACOSX_DEPLOYMENT_TARGET=10.6
make
sudo make install

Then there are various less obvious build issues like third-party libraries that are needed for all of the standard library modules to build and work as expected - GNU readline and bsddb come to mind - so there is no guarantee that you won't run into other problems. 然后,还有各种不太明显的构建问题,例如所有标准库模块都需要按预期进行构建和工作所需的第三方库-GNU readline和bsddb浮现在脑海-因此无法保证您不会遇到其他问题。

$ python2.5
Python 2.5.5 (r255:77872, Sep 29 2010, 10:23:54) 
[GCC 4.0.1 (Apple Inc. build 5494)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Module readline not available.
>>> 

You could try using the installer build script in the source tree (in Mac/BuildScript/ ) but it will likely need to be patched to work correctly on 10.6. 您可以尝试在源代码树(在Mac/BuildScript/ )中使用安装程序构建脚本,但是可能需要对其进行修补才能在10.6上正常工作。

Even though there is no official python.org installer for 2.5.5 (which just has security fixes), there is an OS X installer for 2.5.4 which works fine on 10.6. 即使没有针对2.5.5的官方python.org安装程序(仅具有安全修复程序),也存在针对2.5.4OS X安装程序,其在10.6上运行良好。 Or use the Apple-supplied 2.5.4. 或使用Apple提供的2.5.4。 Or try MacPorts. 或尝试MacPorts。 It will be nice when GAE is supported on current Python versions. 当前的Python版本支持GAE会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM