Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyenv install python 2.7.8 numpy not work #518

Closed
shixudongleo opened this issue Jan 7, 2016 · 5 comments

Comments

Projects
None yet
5 participants
@shixudongleo
Copy link

commented Jan 7, 2016

I have problem with numpy install in pyenv installed python2.

Details:
System: Ubuntu 14.04
Python: pyenv install 2.7.8
Python Env: pyenv virtualenv 2.7.8 test_env
Numpy: pip install numpy

The error is following:

$ python 
Python 2.7.8 (default, Jan  7 2016, 17:45:25) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/core/__init__.py", line 14, in <module>
    from . import multiarray
ImportError: /home/shixd/.pyenv/versions/test_env/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS4_AsUnicodeEscapeString

How should I fix this problem?
The Ubuntu system has python 2.7.6 as default.

@yyuu

This comment has been minimized.

Copy link
Collaborator

commented Jan 7, 2016

@yyuu yyuu closed this Jan 7, 2016

@shixudongleo

This comment has been minimized.

Copy link
Author

commented Jan 8, 2016

The problem in my case is not same as: http://stackoverflow.com/questions/15403273/possible-conflicting-python-installations

$ which python
/home/shixd/.pyenv/shims/python

this is no numpy installed in /usr/local/lib/python2.7/dist-packages

What is the problem causing this? Can pyenv handle it?
What are the additional operations needed for set it up?

@cu39

This comment has been minimized.

Copy link

commented Mar 22, 2016

My case on Mac OS X 10.9.5 and python 2.7.11 was solved with tweaking build options.
First messages I got :

cu39@mbp:~/% pyenv local 2.7.11
cu39@mbp:~/% python
Python 2.7.11 (default, Mar 20 2016, 22:38:41)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
(...)
ImportError: dlopen(/Users/cu39/.anyenv/envs/pyenv/versions/2.7.11/lib/python2.7/site-packages/numpy/core/multiarray.so, 2): Symbol not found: _PyUnicodeUCS2_AsASCIIString

suggests multiarray.so does not have _PyUnicodeUCS2_AsASCIIString which is supported with nm's output (U means Undefined) (reflink) :

cu39@mbp:~/% nm ~/.anyenv/envs/pyenv/versions/2.7.11/lib/python2.7/site-packages/numpy/core/multiarray.so | grep _PyUnicode
0000000000156ae8 d _PyUnicodeArrType_Type
                 U _PyUnicodeUCS2_AsASCIIString
                 U _PyUnicodeUCS2_AsUnicodeEscapeString
                 U _PyUnicodeUCS2_FromUnicode
00000000000dcc50 t _PyUnicode_FromUCS4
                 U _PyUnicode_Type
0000000000150d68 d __PyUnicode_ArrFuncs

BTW python-build (pyenv install) builds them with --enable-unicode=ucs4 (source) #257
You can confirm it in REPL (reflink) :

>>> import sysconfig
>>> sysconfig.get_config_vars()['CONFIG_ARGS']

numpy wheel for OS X have been built for UCS2-enabled python so my case was solved with giving PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 to pyenv install :

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 2.7.11
pip install --upgrade pip
pip install numpy
>>> import numpy

Though this is not a case for Ubuntu in which python deb package is UCS4-enabled, investigations with nm and sysconfig.get_config_vars() may give you some hints.

@agjohnson

This comment has been minimized.

Copy link

commented Apr 22, 2016

The above information by @cu39 resolved my issue. I was receiving the undefined symbol exception on OSX, using tox on top of a pyenv virtualenv. I hit the ImportError exceptions with undefined UCS2 symbols on pyzmq and lxml.etree while rerolling the pyenv/tox envs. Wiping both and rebuilding my Python versions with PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 resolved the issue.

Also, as this was an issue of the wheels being installed from UCS2 builds, installing with pip --no-binary lxml,pyzmq would in theory have the same effect for my case -- that is, if i wanted to special case all of my tox configurations.

I believe pep 513 aims to address this, though I'm not sure what tool support looks like currently.

@kevinzzz007

This comment has been minimized.

Copy link

commented Jul 4, 2016

@cu39 the solution also worked for me, but I had to delete my old virtualenv which was build based on the Python 2.7.11 that didn't have the specified configurations, and build a new virtualenv that's based on the configured Python 2.7.11, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.