ImportError: No module named 'nilearn'

5.5k views Asked by At

I'm trying to plot .nii data using nibabel and nilearn. I'm using python 3.5 and installed both packages successfully. But, when I'm trying to import the module, it's returning -

ImportError: No module named 'nilearn'.

enter image description here

What am I missing here?

4

There are 4 answers

4
Ben On BEST ANSWER

You're probably installing packages into a different Python installation than you're running your code in. Try the following commands:

# Use the pip for the first python on the path.
sudo python3 -m pip install <modules>
python3 <script>

That'll probably be enough to get this script running. However, as you continue to develop more applications, installing and upgrading libraries at the root level will mean break your applications. Look into Virtual Environments to give each application its own copy of Python and libraries. I also highly recommend looking into Anaconda Python and its environment creator conda to do most of this for you.

0
RemiDav On

This is the actual command to use with pip:

pip install -U --user nilearn
0
JackHacks On

If you want to check and see if pip is installing the modules to the right place you can run:

which pip3
which python3

A virtualenv would probably fix the problem.

0
runzhi xiao On

If you are sure about spelling of the module, then you should check whether you installed the module where python program checks. So try:

import sys
for i in sys.path:print(i)

if the path to the module is not in it,add the path in by

sys.path.append('path to your module')