如何在Mac上使用wide-build安装python

时间:2014-08-04 03:51:50

标签: python macos

我发现我的Mac上的Python使用narrow-build构建,这会在我使用re模型时引发字符范围错误。

所以我想在我的Mac上安装wide-build。那么如何在Mac上安装带广泛版本的Python?

2 个答案:

答案 0 :(得分:5)

如果你真的需要在OS X上使用Python 2的“广泛构建”来支持0xffff以上的Unicode代码点,那么你可能必须自己从源代码构建它。我所知道的OS X的大多数发行版都使用默认的“narrow build”;一个例外是MacPorts,它支持广泛构建的变体:

sudo port install python27 +ucs4

从源代码自己构建Python,下载并解压缩the latest Python source tarball并为您的情况设置适当的配置参数。关键的一个是--enable-unicode=ucs4。例如,最小配置可能是:

curl -O https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar xf ./Python-2.7.8.tgz
cd ./Python-2.7.8
./configure --enable-unicode=ucs4 --prefix=/path/to/install MACOSX_DEPLOYMENT_TARGET=10.9
make
make install
cd
/path/to/install/bin/python2.7
Python 2.7.8 (default, Aug  3 2014, 22:27:28)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxunicode
1114111

正如Jason所指出的,当前的Python 3版本始终支持所有Unicode字符。

答案 1 :(得分:3)

如果使用Python3升级到最新版本。在3.3及更高版本中:

  

删除了窄版和宽版Unicode之间的区别。

http://legacy.python.org/dev/peps/pep-0393/