0
R:\src\tools\Swig>python --version
Python 2.7.13

Somewhat similar to "No module named '_<module>'" when importing a SWIG module with embedded Python

The SWIG wrapper looks sensible and I have a DLL with the same name as the wrapper in the test folder.

When I try and run a script with import TestDevice Python gives me a stack trace like so:

`R:\src\tools\Swig>python test.py
Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import TestDevice
  File "R:\src\tools\Swig\TestDevice.py", line 28, in <module>
    _TestDevice = swig_import_helper()
  File "R:\src\tools\Swig\TestDevice.py", line 20, in swig_import_helper
    import _TestDevice
ImportError: No module named _TestDevice`

A .pyc file being being created but that's about as I far as I get. Any thoughts? The 32 bit DLL is built with VS2015Pro and the static multi-threaded runtime as the module will eventually spin up a threadpool.

TAIA.

J Evans
  • 1,090
  • 2
  • 16
  • 36
  • 2
    Dll needs to be named _TestDevice.pyd – Flexo Jun 07 '17 at 18:31
  • More likely, it is due to the location of the generated `_TestDevice.pyd` is never found. It must reside in a location, which is added using `sys.path` in python. Preferably ensure that it resides in the same folder as the generated Python interface – Jens Munk Jun 09 '17 at 22:56
  • Flexo - I discovered this independently but you are the first person to give the correct answer here, make it an answer and I will tick! The salient point is that a Windows .DLL file needs to have a ,PYD extension. Quite why eludes me completely, as does the failure of the import module to report a more sensible and comprehensbile error message! – J Evans Jun 11 '17 at 16:41

0 Answers0