# openmc.Material error when running in Spyder

**URL:** <https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458>\
**Category:** User Support\
**Created:** [September 23, 2021, 9:38am UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458 "2021-09-23T09:38:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yogdog](https://avatars.discourse-cdn.com/v4/letter/y/e480ec/32.png) [@yogdog](https://openmc.discourse.group/u/yogdog)\
**Post date:** [September 23, 2021, 9:38am UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458/1 "2021-09-23T09:38:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![pshriwise](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/pshriwise/32/3863_2.png) [@pshriwise](https://openmc.discourse.group/u/pshriwise)\
**Post date:** [September 27, 2021, 4:24pm UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458/2 "2021-09-27T16:24:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chenchcc](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chenchcc](https://openmc.discourse.group/u/chenchcc)\
**Post date:** [October 24, 2022, 12:26pm UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458/3 "2022-10-24T12:26:42Z")

</div>

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.

```auto
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.

```auto
# processing.py
from define_openmc import define_my_input

define_my_input() 

```

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![chenchcc](https://avatars.discourse-cdn.com/v4/letter/c/ce7236/32.png) [@chenchcc](https://openmc.discourse.group/u/chenchcc)\
**Post date:** [October 24, 2022, 1:08pm UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458/4 "2022-10-24T13:08:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paulromano](https://yyz2.discourse-cdn.com/free1/user_avatar/openmc.discourse.group/paulromano/32/486_2.png) [@paulromano](https://openmc.discourse.group/u/paulromano)\
**Post date:** [October 29, 2022, 1:42am UTC](https://openmc.discourse.group/t/openmc-material-error-when-running-in-spyder/1458/5 "2022-10-29T01:42:10Z")

</div>

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](https://peps.python.org/pep-0420/). 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.
