pythonucs2pyenvucsucs-4

Build Python as UCS-4 via pyenv


I run into this issue ImportError numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS2_AsASCIIString installing Python in a pyenv-virtualenv environment.

In my case, it happens with the matplotlib package instead of numpy (as in the above question), but it's basically the same issue.

The answer given in that question is a simple:

Rebuild NumPy against a Python built as UCS-4.

I don't know how to do this. In this other question it is said that one has to use:

./configure --enable-unicode=ucs4

but I don't know how to use that command along with pyenv.

This issue is also mentioned in pyenv's repo issue list, and a solution given in a comment. Sadly (for me) I can not understand how to apply the fix explained in said comment.

So my question basically is: how do I build Python as UCS-4 via pyenv?


Solution

  • 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 '"