I am working on a fresh ubuntu 24.04 install. I followed the instructions to build from source and can run openmc. I established a venv and when i run pip list I get the following:
(openmc-env) brian@1:~$ pip list
Package Version
asttokens 3.0.0
contourpy 1.3.3
cycler 0.12.1
decorator 5.2.1
endf 0.1.9
executing 2.2.1
fonttools 4.60.1
h5py 3.15.0
ipython 9.6.0
ipython_pygments_lexers 1.1.1
jedi 0.19.2
kiwisolver 1.4.9
lxml 6.0.2
matplotlib 3.10.7
matplotlib-inline 0.1.7
numpy 2.3.3
openmc 0.15.3.dev131+ge9077b137
packaging 25.0
pandas 2.3.3
parso 0.8.5
pexpect 4.9.0
pillow 11.3.0
pip 24.0
prompt_toolkit 3.0.52
ptyprocess 0.7.0
pure_eval 0.2.3
Pygments 2.19.2
pyparsing 3.2.5
python-dateutil 2.9.0.post0
pytz 2025.2
scipy 1.16.2
setuptools 80.9.0
six 1.17.0
stack-data 0.6.3
traitlets 5.14.3
tzdata 2025.2
uncertainties 3.2.3
wcwidth 0.2.14
The openmc api is listed here. But if I launch jupyter-notebook from this environment, it fails on the “import openmc” line:
ModuleNotFoundError Traceback (most recent call last)
Cell In[1], line 3
1 print("Start")
2 get_ipython().run_line_magic('matplotlib', 'inline')
----> 3 import openmc
4 import math
5 import os
ModuleNotFoundError: No module named 'openmc'
I've tried multiple work arounds and have only managed to frustrate myself a great deal. Any help is much appreciated.
Brian
Hi @Brian729,
Just to double-check. Did your installation process include the following steps?
Best,
Patrick
Patrick,
Thank you for your quick reply. I tried the command specified in the documentation, and get the environment error:
brian@1:~/openmc$ python3 -m pip install .
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.12/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
brian@1:~/openmc$
I’ve tried many work arounds (pipx, venv), but with no success. So to answer your question, I’ve tried to do what the documentation states, but what it directs fails.
All the best,
Brian
I hope this helps anyone who runs into this problem. Here are the steps I used to make it work:
- Clean ubuntu install (24.04 in this case)
- Using openmc installation guide, install openmc from source
- Install pip
- Generate the python API from within the openmc directory with: python3 -m pip install . --break-system-packages
- Start a python terminal and validate import openmc with openmc.Sphere call.
- Install IDLE
- Install JupyterLab
- Install default python environment with JupyterLab
- Copy endfb library (nuclear data), openmc programs
- Go to work!
Hope this helps. The installation instructions as written did not work for me.
All the best,
Brian
OK. The above works until you try to do something else with python. Here is proper install using environments. I used this on Linux Mint clean install successfully:
1. Compile OpenMC from source and go through process through sudo make install. You should be able to run openmc and get error message of no xml files found.
2. Go up one directory to the OpenMC build directory (openmc as configured in the OpenMC installation guide)
3. run python3 -m venv /yourpath/openmc to make the python environment. yourpath is configured to where you want to place your venv directory.
4. run source /yourpath/openmc/bin/activate to “turn on” openmc environment. Note prompt adds (openmc)
5. run “python3 -m pip install .” This provides the API and all requirements
6. run pip install notebook
7. Change to the source directory you want to run jupyter notebook from
8. run jupyter notebook. At this point you can make a quick test to import openmc and run it. It should pass with no issues.
9. Deactivate environment with command deactivate.
The issues you had working on Ubuntu 24.04 are because the system installed Python is “locked down” to an extent because it is relied on for certain system utilities related to package management and such. The best you can do to modify it is maybe “sudo apt install python-full”.
But working in a venv, you can install any python package. You’ll need to install python-venv (comes with python-full) in order to create a venv.
In my case, I am recompiling openmc from scratch on Ubuntu 24.04 since I need DAGMC, libMesh, and MPI.
For the python API installation, I rebuilt mpi4py and h5py from source as described in Section 2.5.2 of the User Guide (this is triggered by the --no-binary option to pip). I am trying to target the OpenMPI flavor of MPI so I first apt installed libhdf5-dev, libhdf5-openmpi-dev, openmpi-bin, and libopenmpi-dev. Note that the generic libhdf5-mpi-dev is for MPICH. I uninstalled it lest it interfere somehow. Then, working in a venv:
pip uninstall mpi4py
pip uninstall h5py
MPICC=/usr/bin/mpicc python3 -m pip install --no-binary=mpi4py mpi4py
CC=/usr/bin/mpicc HDF5_MPI=ON python3 -m pip install --no-binary=h5py h5py
If I include HDF5_DIR=/usr on the h5py install, the command fails with unable to find libhdf5.so. Odd.
Finally to install the API as editable, cd to the source directory and
pip install -e .
That works so far for the rudimentary tests I have run so far. Have not done anything to test DAGMC, etc. Here is the cmake command I used to build openmc once I had all the prereqs compiled. I have detailed notes on that process also if anyone is interested.
CXX=/usr/bin/mpicxx HDF5_ROOT=/usr cmake \
-DOPENMC_USE_OPENMP=on \
-DOPENMC_USE_DAGMC=on \
-DOPENMC_USE_MCPL=on \
-DOPENMC_USE_LIBMESH=on \
-DOPENMC_USE_MPI=on \
-DHDF5_PREFER_PARALLEL=on \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=$HOME/local \
-DCMAKE_PREFIX_PATH="$HOME/libMesh_bld;$HOME/dagmc_bld/DAGMC;$HOME/mcpl_bld" \
../src