Jupyter Notebook can't find Python module MDAnalysis

Question:

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:Usersyewroanaconda3envsMinesMDpython.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:Usersyewroanaconda3envsMinesMDpython.exe
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done

# All requested packages already installed.  

Retrieving notices: ...working... done
Asked By: Anthony Nash

||

Answers:

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.

Answered By: Damian Robert
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.