Cannot import ok Python library

Hello.

I am running Python 3.7, FrontPanel to 5.2.2, and have installed the C++ redistributables as required in the documentation. My ok.py and _ok.pyd files from the x64 architecture are in the site-packages directory.

When I try to simply do ‘import ok’ in Python, I get the following error.

Traceback (most recent call last):

File “D:\Anaconda3\lib\site-packages\ok.py”, line 15, in swig_import_helper
return importlib.import_module(mname)

File “D:\Anaconda3\lib\importlib_init_.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

File “”, line 1006, in _gcd_import

File “”, line 983, in _find_and_load

File “”, line 967, in _find_and_load_unlocked

File “”, line 670, in _load_unlocked

File “”, line 583, in module_from_spec

File “”, line 1043, in create_module

File “”, line 219, in _call_with_frames_removed

ImportError: DLL load failed: The specified module could not be found.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File “”, line 1, in
import ok

File “D:\Anaconda3\lib\site-packages\ok.py”, line 18, in
_ok = swig_import_helper()

File “D:\Anaconda3\lib\site-packages\ok.py”, line 17, in swig_import_helper
return importlib.import_module(‘_ok’)

File “D:\Anaconda3\lib\importlib_init_.py”, line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)

ImportError: DLL load failed: The specified module could not be found.

I am using SWIG Version 4.0.2. According to the release notes in my FrontPanel directory Python 3.7 is supported. Am I doing something wrong?

Thanks

EDIT: I don’t know if it matters here, but my ok.py files from the /2.7 folder and the /3.7 folder are exactly the same.
EDIT2: Added more information to the code error block. I hadn’t scrolled up.

I downloaded this tool, and determined that python was not able to find okFrontPanel.dll. Apparently it needs to be in the same directory as my python executable. I was under the impression this was only the case with C/C++ code.

The libraries correctly import now.

1 Like

Great answer. It works!!!