enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
290 stars 97 forks source link

Got a syntax error when ran on Win Server 2019 standard #500

Closed mittu80 closed 9 months ago

mittu80 commented 9 months ago

Hello,

I tried to import module pywifi and its dependancy comtypes but got the following syntax error. init.py line 381 image

Can you help me fix this?

junkmd commented 9 months ago

Hi,

I think that the comtypes in your environment is a quite old version from the time when it supported Python 2.6. By executing pip install -U comtypes, you can update to the current version that natively supports Python 3.x.

mittu80 commented 9 months ago

Hi, Thanks for your answer. yeah using 1.1.7 was intentionally done as i learnt from the the homepage as below: image

I might be wrong here as in mycase its win server and not win CE.

I've tried the latest 1.2.0 as well unfortunately i received a ctypes DLL Load error while using pywifi/_wifiutil_win.py (pls see the below pic) image

I am suspecting the latest rel is not compatible to windows server (virtual pc) as when i ran the same on windows laptop it worked.

another Q: is there any workaround for using the comtypes also on raspberry pi devices(Linux) ? along with windows?

i see pywifi is compatible to both os but not its the dependancy

Thanks for your advice.

junkmd commented 9 months ago

Hi,

I might be wrong here as in mycase its win server and not win CE.

I think that's probably the case. One of the virtual environments I use for my main job is Windows Server, and comtypes is functioning on it.

I've tried the latest 1.2.0 as well unfortunately i received a ctypes DLL Load error while using pywifi/_wifiutil_win.py (pls see the below pic) image

I am suspecting the latest rel is not compatible to windows server (virtual pc) as when i ran the same on windows laptop it worked.

It seems that the absence of wlanapi.dll in your environment is the cause of the error. https://github.com/awkman/pywifi/blob/719baf73d8d32c623dbaf5e9de5d973face152a4/pywifi/_wifiutil_win.py#L39 https://docs.python.org/3/library/ctypes.html#ctypes.WinDLL https://docs.python.org/3/library/ctypes.html#ctypes.LibraryLoader

I googled "wlanapi.dll windows server 2019", and it appears that the absence of wlanapi.dll is a universal issue on Windows Server 2019. https://www.google.com/search?q=wlanapi.dll+windows+server+2019

another Q: is there any workaround for using the comtypes also on raspberry pi devices(Linux) ? along with windows?

Since COM is specific to Windows, it cannot be used on other OS. Please refer to https://github.com/enthought/comtypes/issues/479#issuecomment-1550658623.

It seems that the error was not caused by the latest release version of comtypes, so I will close this issue. If you have any questions other than the error handling syntax, please create another issue.

vasily-v-ryabov commented 9 months ago

Yes, wlanapi.dll is used by pywifi package and its absence should be checked by pywifi. Also windll is a Windows-specific part of built-in package ctypes, not comtypes. So even in this aspect comtypes is not directly involved. But it could be not easily recognizable so you're welcome to get help here if you're in doubt.