How to find out if Python is compiled with UCS-2 or UCS-4?
When built with --enable-unicode=ucs4:
>>> import sys
>>> print sys.maxunicode
1114111
When built with --enable-unicode=ucs2:
>>> import sys
>>> print sys.maxunicode
65535
How to change python from UCS2 to UCS4
Use:
./configure --enable-unicode=ucs4
to configure the source to build with UCS4 support.
From the ./configure --help
output:
--enable-unicode[=ucs[24]]
Enable Unicode strings (default is ucs2)
Build Python as UCS-4 via pyenv
Installing python
with pyenv
with ucs2
:
$ export PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2
$ pyenv install -v 2.7.11
...
$ pyenv local 2.7.11
$ pyenv versions
system
* 2.7.11 (set by /home/nwani/.python-version)
$ /home/nwani/.pyenv/shims/python
Python 2.7.11 (default, Aug 13 2016, 13:42:13)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_config_vars()['CONFIG_ARGS']
"'--prefix=/home/nwani/.pyenv/versions/2.7.11' '--enable-unicode=ucs2' '--libdir=/home/nwani/.pyenv/versions/2.7.11/lib' 'LDFLAGS=-L/home/nwani/.pyenv/versions/2.7.11/lib ' 'CPPFLAGS=-I/home/nwani/.pyenv/versions/2.7.11/include '"
Installing python
with pyenv
with ucs4
:
$ pyenv uninstall 2.7.11
pyenv: remove /home/nwani/.pyenv/versions/2.7.11? y
$ export PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs4
$ pyenv install -v 2.7.11
...
$ pyenv local 2.7.11
$ pyenv versions
system
* 2.7.11 (set by /home/nwani/.python-version)
$ /home/nwani/.pyenv/shims/python
Python 2.7.11 (default, Aug 13 2016, 13:49:09)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_config_vars()['CONFIG_ARGS']
"'--prefix=/home/nwani/.pyenv/versions/2.7.11' '--enable-unicode=ucs4' '--libdir=/home/nwani/.pyenv/versions/2.7.11/lib' 'LDFLAGS=-L/home/nwani/.pyenv/versions/2.7.11/lib ' 'CPPFLAGS=-I/home/nwani/.pyenv/versions/2.7.11/include '"
How to recompile Python2.7 with 4-byte unicode enabled?
From the output of
./configure --help
the correct option is given as
--enable-unicode=ucs4
Related Topics
Should I Call Close() After Urllib.Urlopen()
How to Set Folder Permissions in Windows
What Does the Term "Broadcasting" Mean in Pandas Documentation
Multiple Linear Regression in Python
Full Examples of Using Pyserial Package
How to Declare an Array in Python
Check If a File Is Open in Python
How to Remove an Element in Lxml
Drawing Lines Between Two Plots in Matplotlib
How Can One Continuously Generate and Track Several Random Objects with a Time Delay in Pygame
How to Check If Directory Exists in Python
How to Bind a List to a Parameter in a Custom Query in SQLalchemy
How to Normalize a Numpy Array to a Unit Vector