ZOS-API not compatible with modern versions of Python and pythonnet

  • 17 March 2023
  • 7 replies



I have read this knowledgebase article on how to use pythonnet with ZOS-API. It suggests using Python 3.4 to 3.8. Yet, 3.4 to 3.6 have reached end of life, 3.7 will in 3 months and 3.8 next year. Also, pythonnet 2.5 is no longer maintained. The only active development is focused on version 3+.

I would like to use ZOS-API work with modern versions of Python, 3.10+. The only pythonnet version compatible with them is 3+. Under these versions, quite a few ZOS-API calls are broken. For example, 


raises an exception due to how pythonnet 3+ handles the conversion of int32 and Enum between .NET<->Python.

Is there any way to use ZOS-API with these modern and maintained versions? Note that I don’t believe that using Python 3.8 or 3.9 with pythonnet 2.5.2 is a good solution, because pythonnet 2.5.2 is not actively maintained. The pythonnet team has stated multiple times that features/bugs would only be added/fixed in 3+ (for example here).


Thank you,



Best answer by chaasjes 19 January 2024, 15:20

View original

7 replies

Yes, this needs to be fixed ASAP.

But I’m sure the Zemax SW engineers are working on this, right?

Userlevel 6
Badge +2

Hi @Hans Martinsson and @Miloth ! I have reported this to our product team as Michael H has written a post saying how to use PythonNET 3.x:


Hi @Sandrine Auriol ,

Thank you for the reply. I will have a look at Michael H’s implementation and implement it in the script. Yet, do you have an estimated timeframe for the release of updated API docs and examples reflecting the required changes?

Thanks again.



Userlevel 6
Badge +2

Hi @Miloth 

I have just reported it to the product team so will let you know as soon as we hear back from them.

I was happily running pythonnet 2.5.2 using python 3.8 as a valid and stable combination untill zemax moved to Ansys. 
Now each time I open a zemax file with Ansys Otpic studio the connection is not running anymore. 
With old files (Not opened by Ansys) it does run. 

Any idea what is going on ?

Userlevel 3

Is there any way to use ZOS-API with these modern and maintained versions?


Yes, there is! You can use ZOSPy, which is compatible with all modern Python and Python.NET versions.
The most common problems related with Python.NET 3 were fixed in version 1.0.0, and we recently released ZOSPy 1.2.0, which fixes even more problems:

See also the separate post about these fixes:


[Moderator Note: The ZOSPy is a great tool developed by members of our community. Take the time to check it out! However, it is not maintained formally by Zemax and its developers.]

Hi @chaasjes , thank you for sharing your library. I already knew about it and I like it!

Yet, I do not believe this is a viable solution for production code, because it is not an officially provided from Zemax. For example, we have already encountered multiple occasions where we need to send snippets of code to Zemax support. I doubt the would accept them.

Unfortunately, this means that I do not believe that the answer above can be considered the solution until we have a confirmation from Zemax of their support of ZOSPy.

Thank you for the understanding.