Reputation: 59
I'm new to both Linux and Python. I'm working on a Ubuntu 16.04.
My original Python is
python --version
Python 2.7.8
I'm trying to import numpy into python3. However, when I try to import numpy I get this error
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/numpy/core/init.py", line 16, in from . import multiarray ImportError: /usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: _Py_ZeroStruct
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/numpy/init.py", line 142, in from . import add_newdocs File "/usr/local/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in from numpy.lib import add_newdoc File "/usr/local/lib/python2.7/dist-packages/numpy/lib/init.py", line 8, in from .type_check import * File "/usr/local/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in import numpy.core.numeric as _nx File "/usr/local/lib/python2.7/dist-packages/numpy/core/init.py", line 26, in raise ImportError(msg)
ImportError: Importing the multiarray numpy extension module failed.
Most likely you are trying to import a failed build of numpy. If you're working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.
Original error was:
/usr/local/lib/python2.7/dist-packages/numpy/core/multiarray.so: undefined symbol: _Py_ZeroStruct"
The python I'm using to import numpy is Python 3.5.2 and it seems to be trying to use the package in Python 2.7.
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-numpy
sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall
sudo apt install python3-numpy python3-scipy
It seems a similar problem to what others have faced but none of the solutions seem to work?
Upvotes: 0
Views: 4108
Reputation: 67
You installed pip for both python2.7 and python3. To use pip of python3 just you need to use pip3 instead of pip.
pip3 install package
Upvotes: 1