<div dir="ltr"><div>I'd like to use a driver Python script to call a Python function within a module that uses ParaView to read a file in parallel and I was wondering the best way to go about this.<br><br></div><div>A little background:<br></div><div>The file structure is something like this:<br><br></div><div><span style="font-family:monospace,monospace">mypythonpackage/<br></span></div><div><span style="font-family:monospace,monospace">   scripts/<br></span></div><div><span style="font-family:monospace,monospace">      my_driver_script.py<br>   mypythonpackage/<br></span></div><div><span style="font-family:monospace,monospace">      paraview/<br></span></div><div><span style="font-family:monospace,monospace">         filewithparaviewstuff.py<br></span></div><div><span style="font-family:monospace,monospace">         utilities.py<br></span></div><div><br></div><div>The driver script takes inputs and then calls a function in <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> that uses ParaView to load a large data file and do some data analysis.  I need to load the dataset in parallel since it is quite large.  To get around this in the past I've used two different methods:<br><br></div><div>1. Use the subprocess Python package inside the <span style="font-family:monospace,monospace">my_driver_script.py</span> to call the <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> using <span style="font-family:monospace,monospace">pvbatch</span>.<br></div><div>2. Use the subprocess Python package inside the <span style="font-family:monospace,monospace">my_driver_script.py</span> to start a <span style="font-family:monospace,monospace">pvserver</span> and then connect to this server within the function inside <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span><br><br></div><div>The issue I have is the <span style="font-family:monospace,monospace">filewithparaviewstuff.py</span><span style="font-family:arial,helvetica,sans-serif"> calls some functions in the utilities.py file.  I'm trying to follow <a href="https://www.python.org/dev/peps/pep-0328/">PEP 328</a> and use import statements within </span><span style="font-family:arial,helvetica,sans-serif"><span style="font-family:monospace,monospace">filewithparaviewstuff.py </span>like</span><span style="font-family:monospace,monospace">:<br><br></span></div><div><span style="font-family:monospace,monospace">from .utilities import my_utility_function<br><br></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">inside the </font></span><span style="font-family:monospace,monospace">filewithparaviewstuff.py <font face="arial,helvetica,sans-serif">but this <a href="http://stackoverflow.com/questions/11536764/attempted-relative-import-in-non-package-even-with-init-py">causes problems</a> if I use method 1, of calling the </font></span><span style="font-family:monospace,monospace">filewithparaviewstuff.py<font face="arial,helvetica,sans-serif"> directly with </font>pvbatch<font face="arial,helvetica,sans-serif"> or if I try to make a </font>'__main__'<font face="arial,helvetica,sans-serif"> function in the </font></span><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif"><span style="font-family:monospace,monospace">filewithparaviewstuff.py</span> and call that directly with </font>pvbatch<font face="arial,helvetica,sans-serif">.<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Am I doing something fundamentally wrong or has anyone encountered this situation and come up with a more elegant solution?  If not, should I just keep going with my option 2?<br><br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Thanks,<br></font></span></div><div><span style="font-family:monospace,monospace"><font face="arial,helvetica,sans-serif">Andy<br></font></span></div></div>