Search code examples
pythonnibabelnilearn

ImportError: No module named 'nilearn'


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?


Solution

  • 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.