'ModuleNotFoundError: No module named 'openmc'' error

Hello,
I am getting an error when running openmc for the first time. I am using Ubuntu.
The full error that includes the text in the title is

(openmc-env) blamtruth@homebrew:~/test01$ python pincell_test.py
Traceback (most recent call last):
  File "pincell_test.py", line 4, in <module>
    import openmc
ModuleNotFoundError: No module named 'openmc'
(openmc-env) blamtruth@homebrew:~/test01$ setxs
(openmc-env) blamtruth@homebrew:~/test01$ openmc
 ERROR: Settings XML file 'settings.xml' does not exist! In order to run OpenMC,
        you first need a set of input files; at a minimum, this includes
        settings.xml, geometry.xml, and materials.xml. Please consult the user's
        guide at https://docs.openmc.org for further information.

1 Like

Hello @fruitfly. Your problem is as follows.

  1. You are using the conda environment to run OpenMC, not the installation by building the source. When you used the python pincell_test.py in your terminal, it basically used the system’s inbult python. Your python should be from the conda environment which I think is python3. Type python3 pincell_test.py instead and run again.
  2. As you are using the terminal to run OpenMC, you need atleast 3 XML files which are material.xml, geometry.xml, settings.xml to run the simulation. I personally don’t recommend this. Use Jupyter Lab or Jupyer Notebook to run the simulations.

I hope this helps.

Hello @fruitfly;

as it is mentionned by @fsabab , to be able to run openmc directly by means of python file, the package for python should be build (when openmc is built from source (see section 2.4 from 2. Installation and Configuration — OpenMC Documentation, untill the last step where yous hould the openmc package for python by typing: “>pip install .” ) in such that way you can import openmc as any other python package and running it by using the usual command for any python script will work fine!
for the second problem, i think it beucause the script did not work and the related xml files were not created, that’s why using it under conda environment gave back the corresponding “xml files” message.

Good Luck

1 Like