xzos / PyZDDE

Zemax/ OpticStudio Extension using Python
MIT License
159 stars 67 forks source link

ImportError: bad magic number in 'pyzdde.arraytrace': b'\x03\xf3\r\n' #107

Closed mzechmeister closed 1 year ago

mzechmeister commented 1 year ago

I get this

>>> import pyzdde.arraytrace as at
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: bad magic number in 'pyzdde.arraytrace': b'\x03\xf3\r\n'

The directory content of the arraytrace directory shows pyc files

ArrayDemo.c
arrayTraceClient.c
arrayTraceClient.h
__init__.pyc
raystruct_interface.pyc
Release
x64
zclient.c

(@Stuermer ?)

And in python 2.7:

>>> import pyzdde.arraytrace as at
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\PROGRAMSANDEXPERIMENTS\PYTHON\OPTICS\PyZDDE\pyzdde\arraytrace\__init__.py", line 3, in <module>
  File "C:\PROGRAMSANDEXPERIMENTS\PYTHON\OPTICS\PyZDDE\pyzdde\arraytrace\raystruct_interface.py", line 74, in <module>
AttributeError: 'module' object has no attribute 'WinDLL'
>>> pyzdde

I don't have windows (C:) or folders like PROGRAMSANDEXPERIMENTS\PYTHON\OPTICS

Stuermer commented 1 year ago

I remember that one - and that I fixed it somehow. Never wrote it down, but it required recompiling the DLL. (I think the issue had to do with 32bit vs 64bit environments).

I've attached the new DLL (no guarantee that it will work for your system though). I'm using python 3.

Try putting it in x64/Release folder. And delete all .pyc files (they will get recreated when needed).

ArrayTrace.zip

mzechmeister commented 1 year ago

Doing so, I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/users/zechmeister/.local/lib/python3.9/site-packages/pyzdde/arraytrace.py", line 56, in <module>
    _array_trace_lib = _ct.WinDLL(_dllpath + _dllName)
AttributeError: module 'ctypes' has no attribute 'WinDLL'

Does it only works with window not linux?

Stuermer commented 1 year ago

Since it requires access to ZEMAX OpticStudio it only works under Windows, yes. (same for the DLL stuff).

mzechmeister commented 1 year ago

Ok. The same error occured on windows, too.

As suggested, replacing ArrayTrace.dll and del *.pyc in pyzdde\arraytrace solved the problem.