0

I'm relatively new to Python and am trying to import some modules that were written by a 3rd party. They are called ok.py and _ok.pyd. I am trying to 'import ok', which references _ok.pyd, but it is not working. They are both in my site-packages directory, and I've added that path name to my Spyder PYTHONPATH variable. I've also tried putting them both in the current working directory, but to no avail.

All I do is type 'import ok' and I get the following error messages.

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.

The following is the ok.py code where it fails. I've done an image so line numbers are visible.

ok.py

Is there something easy I'm missing here, or is it unsolvable without the 3rd party vendor updating their code? It just looks like the importlib.import_module() cannot find _ok, but it is in the directory. When I type importlib.import_module() for other module names in that directory it works, so what are possible causes for this one not working?

Thank you.

  • you did activate your conda environment, right? `conda activate` – Daniel Jun 21 '20 at 00:24
  • I did 'conda activate', no change. Other modules in the same directory are imported correctly with the importlib.import_module() method, but this one fails. It just looks like Python isn't able to find the file though, from the DLL load failed error. – Michael Wayne Jun 21 '20 at 00:58
  • You are probably missing a dependent DLL, such as a Visual Studio C runtime. See [this answer](https://stackoverflow.com/questions/18583061/c-dll-loads-in-c-program-not-in-python-ctypes/18650202#18650202) for a way to tell which one. – Mark Tolonen Jun 21 '20 at 18:51
  • Mark, thank you so much. I downloaded this tool and it revealed there was a .DLL file that needed to be in a particular directory. – Michael Wayne Jun 21 '20 at 23:05

0 Answers0