Solved

Unable to connect Python (Spyder) to Zemax

  • 23 December 2022
  • 6 replies
  • 273 views

Hi , 

I am currently trying to use python (Spyder) to connect with Zemax. 

But I am getting the errors below (shown in the picture below) . I can’t find any solution. 
I tried to use another python version - 3.7.0 , but still same error. Both standalone application and interactive extension result in same error messages. 

Appreciate if anyone could give me some guidance. Thank you 

 

 

 

 

 

icon

Best answer by Sandrine Auriol 16 January 2023, 11:21

View original

6 replies

Userlevel 7
Badge +2

Hi Eric,

 

I’m assuming you are generating the tepmlate code from the latest OpticStudio version: Programming > Python > Standalone Application / Interactive Extension.

Can you tell us your version of Pythonnet as well? There have been issues with Pythonnet 3.0.0 and Zemax recommend using Pythonnet 2.5.2 for the moment:

Take care,

 

David

Hi David, 

 

Thank you for the advice. Yes, I am generating the template from that method. 


I have uninstall Pythonnet 3.0.0 and installed 2.5.2. However, the error continue to occur. 

 

Is there any other method/way I could try ? 

Userlevel 3
Badge +2

Hi @Eric.Aw,

I’m wondering if you are missing a required package for Python. In order for clr to work properly, you need to install the Pythonnet library. It could be corrupted as well, so try uninstalling/reinstalling it if you’ve already added it to your Python installation.

There are also some good suggestions here in this Community article: ZOSAPI_NetHelper cannot be added | Zemax Community.

Best,
Ethan 

Userlevel 6
Badge +2

Hi @Eric.Aw 

I had a similar problem and this post helped me: https://stackoverflow.com/questions/47913079/python-attributeerror-module-object-has-no-attribute-addreference

Hi @Ethan , @Sandrine Auriol 

Thank you very much for the advice. 
At the end , I uninstall everything (python and spyder) and install everything again. Then follow some of the guide above and it works. 

 

Thank you 

Userlevel 3
Badge +2

Hi @Eric.Aw,

I’m glad to hear you got it working! Thanks for updating the Community with your findings.

Best,
Ethan

 

Reply