OS X not using most recent NumPY version - python

Trying to update NumPY by running pip install -U numpy, which yields "Requirement already up-to-date: numpy in /Library/Python/2.7/site-packages". Then checking the version with import numpy and numpy.version.version yields '1.6.2' (old version). Python is importing numpy via the path '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy'. Please help me out here.

You can remove the old version of numpy from
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
.
Just delete the numpy package from there and then try to import numpy from the python shell.

The new NumPY version would install (via pip) into the System path, where it wasn't being recognized by Python. To solve this I ran pip install --user numpy==1.7.1 to specify I want NumPY version 1.7.1 on my Python (user) path.
:)

Related

How do import numpys on Jupiter notebook?

Hi everyone im currently facing problems with importing NumPy in jupyter notebook.
My first line of code was import numpy as np it resulted into giving me:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-8b972f5c2406> in <module>
----> 1 import numpy as np
After that my second option was to install NumPy which I did using !pip3 install numpy and that gave me Requirement already satisfied: NumPy in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (1.19.0)
Can someone let me know if I should re-download pip or something is wrong in my files? Thank you.
Check what version of python is your jupyter running.
Its highly likely that its running python 2.x.
If so, try using !pip install numpy instead of !pip3 install numpy.
You need to go to your Terminal, and execute !pip install numpy or pip3 install numpy depending on which version of Python you are using.
In the terminal, check for your python version using below command:
python --version
if you are using version 2 or 3:
python -m pip install numpy
if you are using version 3 or higher:
python3 -m pip install numpy
This way you know about where the package will be installed

Jupyter notebook picks older version of numpy

I am using python 2.7.6 and trying to import pandas but Jupyter notebook gives me following
error--
ImportError Traceback (most recent call
last) in ()
----> 1 import pandas
/usr/local/lib/python2.7/dist-packages/pandas/init.py in
()
21
22 # numpy compat
---> 23 from pandas.compat.numpy import *
24
25 try:
/usr/local/lib/python2.7/dist-packages/pandas/compat/numpy/init.py
in ()
22 'your numpy version is {0}.\n'
23 'Please upgrade numpy to >= 1.9.0 to use '
---> 24 'this pandas version'.format(_np_version))
25
26
ImportError: this version of pandas is incompatible with numpy < 1.9.0
your numpy version is 1.8.2. Please upgrade numpy to >= 1.9.0 to use
this pandas version
while I have numpy 1.14.1
$ pip freeze
numpy==1.14.1
pandas==0.22.0
pip-magic==0.2.3
python-dateutil==2.6.1
pytz==2018.3
six==1.11.0
I have tried uninstalling and then reinstalling numpy and pandas from ubuntu terminal as well as Jupyter's terminal but unable to solve the error, any help would be appreciated. Thanks.
I could imagine that you have different versions of Python on your computer. In the Jupyter Notebook try running
import sys
sys.executable
This will show you which Python interpreter is used
EDIT:
You can install a new kernel for jupyter that uses the correct Python interpreter. First get a list of the existing kernels that you have:
Type jupyter kernelspec list. If the wanted interpreter is not there you will have to install it. To do so use python -m ipykernel install --name <Kernelname> --display-name <Displayname> Note that the python interpreter you are using to run this command must be the python interpreter that you want to be used by the kernel.
Now you are set up!
Start a new notebook and you will find that you can choose this new kernel
After trying multiple things I was able to resolve it.
The issue here was that python2.7 had older version of numpy i.e. 1.8.2 as the error in the question reports.
In python shell I found the path of numpy in use as follow.
import numpy
print numpy.__path__
the output was this path
/usr/local/lib/python2.7/dist-packages/numpy
went to /usr/local/lib/python2.7/dist-packages and deleted numpy using
sudo rm -r numpy
then staying in dist-packages directory I installed numpy 1.14.1 simply with pip.
sudo pip install numpy==1.14.1
this solved my problem.
One way to make sure that you use the right version or jupyter is the -m option of python:
-m mod : run library module as a script (terminates option list)
If this shows NumPy 1.14:
python -m pip freeze
starting jupyter like this should also give you the same version:
python -m jupyter notebook
you can find what versions of python are on your system and in what order they are searched with:
which -a python
Why don't you rm -rf the numpy library and install the version he is asking you too.
sudo pip install numpy==1.14.1

why i still can't use the NumPy module even the terminal says "requirement already satisfied"?

i was using
pip install numpy
to install NumPy on my Mac. Then the terminal says that
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I guess it means Numpy is already installed?
but when i wrote
from numpy import array
a=array([1,3],int)
the python shell says
Traceback (most recent call last):
File "/Users/bamford/Documents/python/untitled-3.py", line 1, in <module>
from numpy import array
builtins.ModuleNotFoundError: No module named 'numpy'
what is going on?
Per the comments, notice that your sys.path includes directories whose names imply they are associated with Python3.6:
[... '/Library/Frameworks/Python.framework/Versions/3.6/lib/pytho‌​n36.zip', ...]
Yet NumPy has been installed in your Python2.7 distribution:
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
(my emphasis) So your Wing101 IDE is using Python3, and not finding NumPy because NumPy has not (yet) been installed in your Python3 distribution.
One solution would be to install NumPy for your Python3 distribution. (Another, might be to configure Wing101 to run Python2.7.) Often, the pip executable associated with Python3 is named pip3 (to distinguish it from a Python2 version called pip.) So you might try
pip3 install numpy
to install NumPy.
Moral of the story: Every pip is associated with a particular Python distribution. pip is a Python script. When run, it calls the Python executable associated with that distribution.
To install modules for a particular Python using pip, you need to call the pip script which is associated with the desired Python executable.
The message pip shows in your system
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Here as you can note, numpy module is installed in python 2.7's directory.
You should install it in python 3.*'s directory. You can try that by
pip3 install numpy
pip3 installs python libraries in python 3.*directory
add sudo at the beginning of command to install it system wide.

how change the module that python uses?

I'm installing caffe2 in a remote server, and I used pip to install a module called Numpy.
The python(2.7.6) is in :
/usr/bin/python
The pip is in :
/usr/local/bin/pip
when I use 'pip show numpy':
Name: numpy
Version: 1.13.0
Location: /usr/local/lib/python2.7/dist-packages
but when I try to import it in python:
>>> import numpy as np
>>> n.__version__
'1.8.2'
>>>>>> n.get_include()
'/usr/lib/python2.7/dist-packages/numpy/core/include'
so I tried export PYTHONPATH in relative rc files:
export PYTHONPATH="/usr/local/lib/python2.7/dist-packages":$PYTHONPATH
but this doesn't help.
What's the next step should I take?
The way to avoid all this confusion is to always use a virtualenv, and install the correct version of numpy there.

Updating numpy on MacOS X

I'm trying to update numpy from version 1.6.2 to 1.8.1. My first attempt was to do
sudo pip uninstall numpy
and then install it again with pip. But when I check the version I get the old one:
import numpy as np
np.__version__
'1.6.2'
Then, I tried to
sudo easy_install -U numpy
but I get an error:
RuntimeError: Broken toolchain: cannot link a simple C program
The path to the numpy version I use is: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
So, is the solution to manually install (from source) the desired version of Numpy or is there a way to use pip or easy_install?

Categories

Resources