Home > Mobile >  Jupyter Notebook can't find Python module MDAnalysis
Jupyter Notebook can't find Python module MDAnalysis

Time:10-30

I'm very sorry, this question has popped up quite a few times, yet I'm still struggling. I'm using Windows 11. I've installed Anaconda Navigator, created a new environment, and installed the required module (MDAnalysis, via Anaconda Navigator). I launched Juypter Notebook from the play icon of the desired environment inside Anaconda Navigator.

Then with the code:

import sys
print(sys.executable) 

#!pip install mdanalysis
import mdanalysis as md

Which returns the error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In [1], line 6
      1 import sys
      2 print(sys.executable) 
      3 
      4 #!pip install mdanalysis
----> 6 import mdanalysis as md

ModuleNotFoundError: No module named 'mdanalysis'

As you can see, from printing out the sys.executable and checking whether mdanalysis is installed (it is; hence I commented the pip line out), I've tried attempts mentioned elsewhere in StackOverflow with no success.

The executable is:

C:\Users\yewro\anaconda3\envs\MinesMD\python.exe

Where MinesMD is the conda environment, I (a) installed MDAnalysis from Anaconda Navigator, and (b) I launched Jupyter Notebook.

I would appreciate any help/suggestions.

EDIT I've just tried installing MDAnalysis via conda inside Jupyter Notebook. I shouldn't need to do this as I did it within Anaconda Navigator (and with the right environment), but in for a penny, in for a pound. This is the output (matching python executable location and environment):

C:\Users\yewro\anaconda3\envs\MinesMD\python.exe
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

# All requested packages already installed.  

Retrieving notices: ...working... done

CodePudding user response:

Try installing the missing package directly from the Jupyter Notebook (with pip or conda) as explained here: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/

EDIT: We figured out that the package was correctly installed and accessible to the Jupyter Notebook environment. (See comments for this answer)

The problem is that the modules import should be different: import MDAnalysis instead of import mdanalysis.

  • Related