Running a python script as headless without pvpython/pvbatch

I’m working on a Paraview project that runs as a Python script. It’s crashing when I try using it in a CAVE and I believe it’s because of the VTK Render window it’s opening whenever it runs. I want to stop this window from opening and I’ve seen this can be done by running the script in headless mode with --force-offscreen-rendering in pvpython or with pvbatch. The problem is I have packages that I need to include that pvpython doesn’t have:
mcp[cli]>=1.10.0,<2.0.0
httpx>=0.24.0
Pillow>=9.0.0
fastmcp
I’ve been creating a virtual environment, pip installing said packages, and then copy pasting the files from site-packages in paraview to the site-packages in the venv. This has been working fine for my uses except I can’t figure out how to run my script as headless with this setup.

I’ve seen other people using venvs with pvpython but it hasn’t worked for me. I get errors like this.

>> import mcp

Traceback (most recent call last): File “”, line 1, in File “C:\Users\raw17\paraview_mcp\venvs\paraview_mcp_test2\Lib\site-packages\mcp_init_.py”, line 1, in from .client.session import ClientSession File “C:\Users\raw17\paraview_mcp\venvs\paraview_mcp_test2\Lib\site-packages\mcp\client\session.py”, line 6, in import anyio.lowlevel File “C:\Users\raw17\paraview_mcp\venvs\paraview_mcp_test2\Lib\site-packages\anyio_init_.py”, line 35, in from ._core._sockets import TCPConnectable as TCPConnectable File “C:\Users\raw17\paraview_mcp\venvs\paraview_mcp_test2\Lib\site-packages\anyio_core_sockets.py”, line 6, in import ssl File “C:\t\ParaView-6.0.1-MPI-Windows-Python3.12-msvc2017-AMD64\bin\Lib\ssl.py”, line 100, in import _ssl # if we can’t import it, let the error propagate ^^^^^^^^^^^ ModuleNotFoundError: No module named ‘_ssl’

Is there anyway to run my python script as headless? I really don’t want to have to compile my own version.

(Windows, 6.0.1 MPI version) (I also tried copying _ssl.pyd into the bin directory and that didn’t work)

The best approach is to add your venv along with the paraview one.

See https://www.kitware.com/using-python-virtual-environments-in-paraview-5-13-0/

The only constraint is to make your venv with the same python version as ParaView (3.12).

Sorry I missed the bottom section of your post… Indeed SSL is not part of ParaView, which force you to run from your venv and add PYTHONPATH/LD_LIBRARY_PATH (for Windows PYTHONPATH/PATH).

So for the offscreen, if you can get your hand on the RenderWindow before any render call, you can turn them off. There might also be a ENV variable that you could set?

Another path is to use conda and install ParaView from there.

I realized I was putting the _ssl.pyd into the bin folder instead of the DLLs folder but that just moved the issue and I started getting this error:
Error running MCP server: ‘vtkPythonStdStreamCaptureHelper’ object has no attribute ‘buffer’

Gemini said it was something to do with Paraview capturing STDIN which would garble the MCP calls but I’m not sure if it was hallucinating or not. I tried a couple of the solutions that it mentioned but none of them worked.

How do I, “get my hand on” the RenderWindow? I tried just hitting the x before after starting the MCP server but it wouldn’t close. I don’t believe there where any render calls before I tried it as the pvpython had just started.

As for the ENV variable you mentioned, I tried:
os.environ[“VTK_DEFAULT_OPENGL_WINDOW”] = “vtkGenericOpenGLRenderWindow”

but it didn’t do anything.

I’m at NIST and we can’t use Conda.