Python API issues

I have a python input file that runs successfully and generates xml input files when using the python package that comes from the conda installation. However, I would like to use openmc on a cluster with mpi, so I had to compile from source. I followed the instructions, making sure I included “-DOPENMC_USE_MPI=on” in my cmake command. After compiling, I installed the python APIs using “pip install .” while in the base directory of the openmc repo. However, when I go to run the same python input file to generate xml inputs, I get the traceback shown below. What am I doing wrong?

Traceback (most recent call last):
File “mgxs_micro_empire_CR_FW_dep.py”, line 4, in
import openmc.deplete
File “/home/behnpa/.local/lib/python3.7/site-packages/openmc/init.py”, line 36, in
from .config import *
File “/home/behnpa/.local/lib/python3.7/site-packages/openmc/config.py”, line 92, in
config = _default_config()
File “/home/behnpa/.local/lib/python3.7/site-packages/openmc/config.py”, line 81, in _default_config
data = DataLibrary.from_xml(config[‘cross_sections’])
File “/home/behnpa/.local/lib/python3.7/site-packages/openmc/data/library.py”, line 169, in from_xml
tree = ET.parse(path)
File “src/lxml/etree.pyx”, line 3521, in lxml.etree.parse
File “src/lxml/parser.pxi”, line 1882, in lxml.etree._parseDocument
TypeError: cannot parse from ‘PosixPath’

This looks like a Path object from the pathlib library is being passed in to an Element tree (ET) function that expects a string. Not sure what the solution here is, it might need some testing and changes to the source code. Can I ask which version of the Openmc source code you are installing, is it from the main or develop branch or another branch?

I actually ran into this too yesterday. If you update the lxml package in your Python environment, that should do the trick.

1 Like

Updating my lxml package resolved the issue. Thanks!