5

I've used pip to install the module numpy (sudo pip install numpy).This works fine.

When importing numpy for use in my own module i get several the following errors.

 Traceback (most recent call last):
  File "<pyshell#65>", line 1, in <module>
    import numpy
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/__init__.py", line 14, in <module>
    from . import multiarray
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so, 2): Symbol not found: _PyBuffer_Type
  Referenced from: /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so
  Expected in: flat namespace
 in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/numpy/core/multiarray.so

I'm assuming the error has something to do with the multiarray.so file. I've tried turning it off and on (uninstall re install) and adding the where pip initially saves the module to python export path

(export PYTHONPATH="usr/local/lib/python2.7/site-packages")

doesn't seem to work.

Using which python in terminal gives me Python 2.7.6**, however I downloaded python 3.5 off of the site.

2
  • 1
    You should run the version of Python for which you installed Numpy using pip. For python 3.5, you may have the commands pip3, pip3.5, python3.5 available. If you are setting PYTHONPATH to point to Python 3.5 directory and trying to run Python 2.7, or manually copying files from Python 2.7 directory to Python 3.5, don't do that --- it does not work. Also, instead of sudo pip install, prefer pip install --user. Commented Oct 17, 2015 at 17:09
  • Hi, thanks for replying. "manually copying files from Python 2.7 directory to Python 3.5" is exactly what I'm doing, and it works for other modules such as NLTK and works for the most part for numpy. The issue i feel lies with the multiarray.so file? Also, I've used pip install --user (and have it noted for the future), i get this message "Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5". So it knows i have numpy installed, the directors listed is recognised by my python module in sys.path also. Any Suggestions? Commented Oct 17, 2015 at 19:30

4 Answers 4

4

Issue resolved.

The reason i was having installation issues with pip, was down to the fact (thanks pv) that i was using the command:

"pip install moduleName"

rather than

"pip3.5 install moduleName"

this caused all sorts of complications, because i'm running python 3.5 and the "pip" command is for 2.7.

Thanks again.

Sign up to request clarification or add additional context in comments.

1 Comment

Remove the old numpy first with 'pip uninstall numpy'.
0

FWIW -- and for people in the future who are googling for this error -- I ran into this issue when installing numpy separately via Homebrew. It caused all my installations of Python (via pyenv) to refer to the /usr/local/lib installation of numpy (which is where Homebrew installs it). Uninstalling it via brew uninstall numpy fixed the error.

(I don't remember why I had a homebrew-installed numpy, but oh well)

Comments

0

I encountered the same problem.

I tried many ways like:

$pip uninstall numpy

But that did not fix the problem.

I assume a major reason is that I have anaconda multi-Python environments (I have created both py27 and py35). As a result the PYTHONPATH includes paths for both py27 and py35.

My default python env is py35. So using

$conda install numpy

will install numpy under the anaconda python3.5 path.

When uninstalling the numpy, we are not sure which numpy path is exporting, maybe it is only for my case.

Hence I refer to @Dan Nhuyen's solution.

I uninstall numpy via:

$brew uninstall numpy.

As a result, the extra ambiguous paths is removed. Finally, it works.

Comments

0

What worked for me was to request pip to build numpy from source, instead of using the pre-compiled wheel binary:

pip install --no-binary numpy -r requirements.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.