No module named mpi4py

600 views
Skip to first unread message

Jinshi Chen

unread,
Dec 27, 2019, 5:37:38 PM12/27/19
to Dedalus Users
Hi,

I am sorry to bother the whole group again. I am still trying to install dedalus on Ubuntu 18.04 but unfortunately none of the 4 methods mentioned in the project website seems to work. I have "successfully installed" dedalus using installation script, but when I run the first tutorial notebook, the code failed at the first line (from dedalus import public as de). The error message is:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ffff509c6591> in <module>
----> 1 from dedalus import public as de

~/dedalus/src/dedalus/dedalus/public.py in <module>
      5 
      6 # Import custom logging to setup rootlogger
----> 7 from .tools import logging as logging_setup
      8 
      9 from .core import future as _future

~/dedalus/src/dedalus/dedalus/tools/logging.py in <module>
      6 import pathlib
      7 import logging
----> 8 from mpi4py import MPI
      9 import os
     10 import sys

ModuleNotFoundError: No module named 'mpi4py'


I have installed mpi4py via pip3 previously. Thus I have no idea why the system is not able to find mpi4py. Could someone please tell me what's going on?

Thank you so much!

Best,
Jinshi

Daniel Lecoanet

unread,
Dec 27, 2019, 6:05:56 PM12/27/19
to dedalu...@googlegroups.com
Hi Jinshi,

Normally this happens when the pip used to install mpi4py installs it for a different version of python than the one used by jupyter. If you installed Dedalus using conda, did you activate the dedalus conda environment? If so, are you running jupyter from the conda-installed python?

Daniel

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/041f34d4-a8d3-4c0e-843d-cf981aab2681%40googlegroups.com.

Jinshi Chen

unread,
Dec 27, 2019, 8:35:54 PM12/27/19
to Dedalus Users
Hi Daniel,

Thank you for your response!

I did try all 4 methods (PyPI, source, conda, script). Thus I used pip3 to install mpi4py when I tried to meet the requirement for installation using PyPI. For conda installation, however, I used anaconda3 platform, and activated the environment before running the tutorial. I am not sure whether I am using jupyter (Jupyter Notebook to be exact) from conda-installed python or not, but I did open the jupyter notebook from Anaconda.

Yet, the problem that I had above (No module named mpi4py) happened when I used the installation from script method. Yet I also used Jupyter Notebook from Anaconda3.

Best,
Jinshi
To unsubscribe from this group and stop receiving emails from it, send an email to dedalu...@googlegroups.com.

Daniel Lecoanet

unread,
Dec 27, 2019, 10:26:58 PM12/27/19
to dedalu...@googlegroups.com
Hi Jinshi,

By trying lots of different strategies, you've probably installed many different versions of python on your computer, which is likely what is causing the problem. The error you're getting suggests the version of jupyter you're using is not linked up to a version of python with mpi4py.

The conda installation is the most robust, so let's try to get that to work. If you activate the dedalus conda environment, and you run "which jupyter" what do you get? Is it something within the conda environment? If not, you need to install jupyter. You can do this using pip. You should make sure that pip installs to the conda environment, and not some other system python. For instance, on my laptop, even when I'm in the dedalus conda environment "pip3" installs to a system python, whereas "pip" installs things to the conda environment's version of python. So "pip3 install jupyter" will not allow me to run jupyter notebooks using Dedalus. Instead, I would need to use "pip install jupyter". Again can you check this with "which pip3" and "which pip". If you can successfully verify that jupyter is running through the conda environment, are you able to run a tutorial notebook?

Daniel

On Fri, Dec 27, 2019 at 8:36 PM Jinshi Chen <jc2...@cornell.edu> wrote:
Hi Daniel,

Thank you for your response!

I did try all 4 methods (PyPI, source, conda, script). Thus I used pip3 to install mpi4py when I tried to meet the requirement for installation using PyPI. For conda installation, however, I used anaconda3 platform, and activated the environment before running the tutorial. I am not sure whether I am using jupyter (Jupyter Notebook to be exact) from conda-installed python or not, but I did open the jupyter notebook from Anaconda.

Yet, the problem that I had above (No module named mpi4py) happened when I used the installation from script method. Yet I also used Jupyter Notebook from Anaconda3.

Best,
Jinshi

On Friday, December 27, 2019 at 6:05:56 PM UTC-5, Daniel Lecoanet wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to dedalu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.

Jinshi Chen

unread,
Dec 28, 2019, 8:10:05 AM12/28/19
to Dedalus Users
Hi Daniel,

Thank you for your reply!

The result of "which jupyter" on my computer is:

/home/jinshi/anaconda3/bin/jupyter

which is the conda version that I am using.

The result of "which pip" is:

/home/jinshi/anaconda3/envs/dedalus/bin/pip

but the result of "which pip3" is

/usr/bin/pip3

which is similar to your condition. However, when I run a jupyter notebook via anaconda3 (with dedalus environment activated), I still failed at the first step. The error message is

No module named 'dedalus'


Best,
Jinshi

Daniel Lecoanet

unread,
Dec 28, 2019, 10:42:18 AM12/28/19
to dedalu...@googlegroups.com
Ok, this is along the lines of what I expected. Your jupyter is linked up to anaconda's python, not Dedalus' python. When you're running jupyter, you're not using the Dedalus environment. I think you can install juypter using "pip install jupyter" and then that version of jupyter should be installed in the Dedalus environment.

Daniel

On Sat, Dec 28, 2019 at 8:10 AM Jinshi Chen <jc2...@cornell.edu> wrote:
Hi Daniel,

Thank you for your reply!

The result of "which jupyter" on my computer is:

/home/jinshi/anaconda3/bin/jupyter

which is the conda version that I am using.

The result of "which pip" is:

/home/jinshi/anaconda3/envs/dedalus/bin/pip

but the result of "which pip3" is

/usr/bin/pip3

which is similar to your condition. However, when I run a jupyter notebook via anaconda3 (with dedalus environment activated), I still failed at the first step. The error message is

No module named 'dedalus'


Best,
Jinshi

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.

Jinshi Chen

unread,
Dec 28, 2019, 4:01:26 PM12/28/19
to Dedalus Users
Hi Daniel,

I have fixed the issue following your suggestions. Thank you so much!

Best,
Jinshi

Rundong

unread,
Nov 3, 2023, 7:28:31 AM11/3/23
to Dedalus Users
Hi Daniel and Jinshi,

Sorry for bring up this old thread. I ran into a similar issue when importing dedalus in jupyter notebook. The error message gives

--------------------------------------------------------------------------- ImportError Traceback (most recent call last) /projects/0/pof/rzhou/k_flow_aspect_passive_scalar/single/F=0.016_k=1/test.ipynb Cell 1 line 5 3 import matplotlib.pyplot as plt 4 # import cmocean ----> 5 import dedalus.public as d3 6 # from mpi4py import MPI 8 from matplotlib import rc File ~/.conda/envs/dedalus3/lib/python3.11/site-packages/dedalus/__init__.py:11 8 __version__ = "3.0.0a" 10 # Import custom logging to setup rootlogger ---> 11 from .tools import logging as _logging_setup 12 import logging 13 logger = logging.getLogger(__name__.split('.')[-1]) File ~/.conda/envs/dedalus3/lib/python3.11/site-packages/dedalus/tools/logging.py:6 4 import pathlib 5 import logging ----> 6 from mpi4py import MPI 7 from ..tools.config import config 9 MPI_RANK = MPI.COMM_WORLD.rank ImportError: libmpi.so.40: cannot open shared object file: No such file or directory

I checked using 'which' command for jupyter, pip, and pip3 under the dedalus environment, I got:

~/.conda/envs/dedalus3/bin/jupyter
~/.conda/envs/dedalus3/bin/pip
~/.conda/envs/dedalus3/bin/pip3

I also used "pip install jupyter" under the dedalus environment as Daniel suggested, and it was installed succesfully. However, the error was still not fixed.

I wonder if anyone how can I fix this?

Thanks!
Rundong

Reply all
Reply to author
Forward
0 new messages