openmc.Material error when running in Spyder

I’ve exported a Jupyter Notebook to a .py format that I’m trying to run in Spyder, but I’m running into an error. When trying to create the first cell, I get an error saying:
File “/home/yogdog/Documents/openmc/Depletion files to send/cladding material/test/claddingmaterial-pe16.py”, line 93, in
fuel_cell = openmc.Cell(fill=fuel_salt, region=fuel_region,name=‘fuel cell’)
File “/home/yogdog/.local/lib/python3.8/site-packages/openmc/cell.py”, line 105, in init
self.fill = fill
File “/home/yogdog/.local/lib/python3.8/site-packages/openmc/cell.py”, line 280, in fill
elif not isinstance(fill, (openmc.Material, openmc.Lattice,
AttributeError: module ‘openmc’ has no attribute ‘Material’

Any ideas why this is happening? For reference, this is the line of code being run that causes the error:
fuel_cell = openmc.Cell(fill=fuel_salt, region=fuel_region,name=‘fuel cell’)

There were no problems in creating the fuel_salt material, so I’ve got no idea what’s going on.

Hi @yogdog and welcome to the discourse forum!

That’s an odd error to see coming from a call to the openmc module. A couple of possibilities come to mind when looking at that trace:

  1. the name associated with the OpenMC module (openmc) has been updated to something else by mistake. I’d need to look at the entire Python file you’re running to see.

  2. Something went wrong with your OpenMC installation and the material.py file is missing under /home/yogdog/.local/lib/python3.8/site-packages/openmc/. This is an easy one to check.

If you’re able to share your Python script I’d be happy to give it a try and see what’s going on.

-Patrick

Sorry to open this topic again.
I have just updated to openmc version 13.2, but the files that I was able to run normally days ago suddenly cannot run. The program gives a similar prompt.

Traceback (most recent call last):
  File "/home/cchen/Desktop/my_openmc/processing.py", line 12, in <module>
    define_my_input() 
  File "/home/cchen/Desktop/my_openmc/define_openmc.py", line 14, in define_my_input
    un_original = openmc.Material(material_id=1, name='UN')
AttributeError: module 'openmc' has no attribute 'Material'

My input file is processed as follows: use a post-processing file, processing.py, to call define_openmc.py file, while the define_openmc.py file, a function containing material, geometry, tally and setting is defined.

# processing.py
from define_openmc import define_my_input

define_my_input() 
# define_openmc.py
import numpy as np
import pandas as pd
import openmc

def define_my_input():
    un_original = openmc.Material(material_id=1, name='UN')
    un_original.add_element('U', 1.0, enrichment=90.3)
    un_original.add_element('N',1.0)
    un_original.set_density('g/cm3',un_density*percent_td)
...
    openmc.run(threads=128)

    return 0

Well, when I rolled back openmc to version 13.1, I found that this problem still exists.

One thought that comes to mind — if you’re running Python from a directory where you have an openmc subdirectory, Python will treat it as a so-called implicit namespace package. If this is indeed the case, you’ll either need to rename that directory so it doesn’t conflict with import openmc or run your script from a different directory.