ModuleNotFoundError: No module named 'numpy' But numpy module already installed - python

Error (img)
I have already installed numpy module
pip show numpy (img)
this how it shows when i try to install numpy again(img)
I tried to import numpy module which is already installed but it throws ModuleNotFoundError

This sounds like a classic case of multiple Python versions on the same machine.
Try a
pip --version
as well as a
python -m pip --version
and a
python --version
my guess is that the associated versions of Python are different (note the pip version won't be the same as the Python version: pip --version on my machine gives: 'pip 22.3.1 from /opt/homebrew/lib/python3.10/site-packages/pip (python 3.10)'). This is often the case where the user has an installed version, and the system comes with a version too; Macs often have this problem, for example.
My thoughts are to try
python -m pip install numpy
which should use a version of pip associated with the Python version you are using. If you want to play more with multiple Python versions, I recommend using pyenv or conda, which will allow multiple versions to be installed simultaneously with a better-defined separation.

Related

How to find python packages correct version for particular python version

I am having python 2.7 and also python 3.6. For an example i want numpy to be installed in my system.My doubt is like any dependency for python 2.7--numpy(example numpy version 1.0) and python 3.6 --numpy (example numpy version 1.16).Not only for numpy but for all packages.If it is any dependency how i can find that version.
Your dependency manager (pip) should take care of this automatically. Just install a package with either
python -m pip install numpy
or
python3 -m pip install numpy
pip automatically selects the correct version of the module to install and all subdependencies.

Trouble importing module in Python 2.7

My Mac computer has Python 3.6 and Python 2.7 and I have successfully installed the basic modules such as numpy, scipy and matplotlib, for example, by doing the routine pip install and pip3 install. My Python 3.6 works totally well in Anaconda-Jupiter-Notebook, IDLE and Terminal, while Python 2.7 works only in terminal but not in IDLE.
Then for version check I tried
pip --version
Returning:
pip 10.0.1 from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip (python 2.7)
pip3 --version
Returning:
pip 10.0.1 from /Users/son520804/anaconda3/lib/python3.6/site-packages/pip (python 3.6)
Then,
which python2
Returning:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
which pip2
Returning:
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip2
How could I resolve this issue and enable the Python 2.7 idle to import the modules? Much appreciated for your help.
find / -iname '*numpy*'
This is a terminal operation not a python command, you can try running that in the terminal to see where it's storing numpy, but you'll probably get the python3's version.
Try:
pip2 uninstall numpy
Then:
pip2 install numpy
It might be due to your machine seeing python3 as your default "python" so pip might actually be installing it again to python3. By denoting pip2 it should be linked to python2 (might actually need to do 'pip2.7'). Hope it helps!
Perhaps your pip is an alias to pip3. Find it out by pip --version and if so install packages for python 2.7 as pip2.7 install matplotlib

ImportError: No module named mako.util when running airflow

I'm trying to follow the tutorial on here: http://pythonhosted.org/airflow/tutorial.html
but i'm using a mac, and so i had to install python via brew, which then comes with pip, which i used to install airflow. However, that didn't quite work either, so i then tried to create a virtualenv for which i tried to install airflow and it is still giving me this ImportError: No module named mako.util
not sure if it matters, but here's my setup:
(airflow) [davidtian: airflow]$ python --version
Python 2.7.12
(airflow) [davidtian: airflow]$ pip --version
pip 8.1.2 from /Users/someone/Desktop/blah/airflow/airflow/lib/python2.7/site-packages (python 2.7)
(airflow) [davidtian: airflow]$
How do i install this mako.util module?
Finally figured it out. after trying a bunch of things. for one, the python that comes with Mac apparently doesn't work very well. you have to brew install python instead. with that python, it comes with pip by default
i had to actually sudo pip uninstall airflow and then install it again.

import graph tool doesn't work on iPython

I installed graph-tool on ubuntu. When trying to import it in iPython I get an error:
ImportError: No module named graph_tool.all
As I read in other posts it might be possible that I used a different version of python for installing graph-tools than the system version I'm using. My question is now, how do I check which version graph-tool is installed with and how do i change this in order to import it?
Thanks for any advice!
If you install using pip you can check
pip -V
result (for example)
pip 8.0.2 from /usr/local/lib/python3.5/dist-packages (python 3.5)
You should have pip, pip2, pip2.7, pip3, pip3.4, etc. to install with different Python.
(in bash write pip and press tab twice to see all programs started with pip)

install python package to a specific version of python?

I have a remote machine with python 2.6 as the default package on the machine. I installed numpy using yum install numpy.
I then installed python 2.7 using the instructions available python 2.7 install link in the directory /usr/src/. I then put this alias
alias python=/usr/src/Python-2.7.8/python
in ~/.bashrc.
So numpy is already installed on the machine but python 2.7 can't pick it up? Should I uninstall it? How do I install it for version 2.7.
The commands would be vary helpful.
Could I pip install to a specific version? I tried this command but it is incorrect.
pip-2.7 install numpy
Thanks
you can do
pythonx.y -m pip install numpy
to install numpy on python version x.y

Categories