Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I fix the 'No module named numpy' error when importing it in Anaconda Python?

ModuleNotFoundError: No module named ‘numpy’ on mac

Hello,
I’ve already dowloaded anaconda in my macbook, but when I try to run the session:


# Numpy is the main package for scientific computing with Python.
import numpy as np


#from skimage import io


# Imports all the methods we define in the file a1code.py
from a1code import *


# Matplotlib is a useful plotting library for python
import matplotlib.pyplot as plt
# This code is to make matplotlib figures appear inline in the
# notebook rather than in a new window.
%matplotlib inline
plt.rcParams['figure.figsize'] = (10.0, 8.0) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams['image.cmap'] = 'gray'


# Some more magic so that the notebook will reload external python modules;
# see http://stackoverflow.com/questions/1907993/autoreload-of-modules-in-ipython
%load_ext autoreload
%autoreload 2
%reload_ext autoreload

I got the error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[2], line 2 1
# Numpy is the main package for scientific computing with Python. ----> 2 import numpy as np 4
#from skimage import io 5 6
# Imports all the methods we define in the file a1code.py 7 from a1code import * ModuleNotFoundError: No module named 'numpy'

but I downloaded numpy:

python -m pip install numpy
Requirement already satisfied: numpy in /Users/yuqingchen/anaconda3/lib/python3.10/site-packages (1.23.5)

and I also used the command line: conda install numpy

but it doesn’t work for me

I am not sure which part cause this error. Any help is appreciated.

>Solution :

Verify the install first with below command.

conda list numpy

Then if you dont see the numpy module, install it using below command.

conda install numpy

Then activate your conda environment to make sure it reflects the change.

conda activate <your_environment_name>

Then import your package in code.

import numpy

Good luck!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading