我发现我的Mac上的Python使用narrow-build构建,这会在我使用re模型时引发字符范围错误.
所以我想在我的Mac上安装广泛的版本.那么如何在Mac上安装广泛的Python?
如果你真的需要OS X上的Python 2"广泛构建"以支持上面的Unicode代码点0xffff,你可能必须自己从源代码构建它.我所知道的OS X的大多数发行版都使用默认的"narrow build"; 一个例外是MacPorts,它支持广泛构建的变体:
sudo port install python27 +ucs4
Run Code Online (Sandbox Code Playgroud)
要从源代码自己构建Python,请下载并解压缩最新的Python源代码tarball,并为您的情况设置适当的configure参数.关键是--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
Run Code Online (Sandbox Code Playgroud)
Run Code Online (Sandbox Code Playgroud)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字符.
如果使用Python3升级到最新版本。在 3.3 及更高版本中:
窄和宽 Unicode 构建之间的区别已被放弃。
http://legacy.python.org/dev/peps/pep-0393/