0

I am trying to run a "homemade" package I recently received. It is native C++ code wrapped with SWIG. EDIT: I have installed all the C++ dependencies required. I know that the package works, as it was previously set-up in other computers.

The code found in __ init __.py is as follows:

 from sys import version_info
 if version_info >= (2, 6, 0):
     def swig_import_helper():
         from os.path import dirname
         import imp
         fp = None
         try:
             fp, pathname, description = imp.find_module('_Pack',      [dirname(__file__)])
         except ImportError:
             import _Pack
             return _Pack

         if fp is not None:
             try:
                 print ('_Pack', fp, pathname, description)
                 _mod = imp.load_module('_Pack', fp, pathname, description)
             finally:
                 fp.close()
             return _mod
     _Hydra = swig_import_helper()
     del swig_import_helper
 else:
     import _Hydra
 del version_info
 try:
     _swig_property = property
 except NameError:
     pass  # Python < 2.2 doesn't have 'property'.`

When I run it, I get the following error:

 C:\Users\jun\Documents\_test>python __init__.py



 Traceback (most recent call last):
   File "__init__.py", line 42, in <module>
     _Pack = swig_import_helper()
   File "__init__.py", line 35, in swig_import_helper
     _mod = imp.load_module('_Pack', fp, pathname, description)
   File "C:\Users\jun\AppData\Local\Programs\Python\Python35-32\lib\imp.py",
 line 242, in load_module
     return load_dynamic(name, filename, file)
   File "C:\Users\jun\AppData\Local\Programs\Python\Python35-32\lib\imp.py",
 line 342, in load_dynamic
     return _load(spec)
   File "<frozen importlib._bootstrap>", line 693, in _load
   File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
   File "<frozen importlib._bootstrap>", line 577, in module_from_spec
   File "<frozen importlib._bootstrap_external>", line 914, in create_module
   File "<frozen importlib._bootstrap>", line 222, in           

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

This error was generated in Windows 7 64-bit, using Python 3.5.3-32 bit. My observation was that the problem lies in load_module, but I really cannot pinpoint why the module cannot be loaded. Any ideas?

kostas
  • 101
  • 12
  • Is your extension built for Python 3.5 32-bit? A 64-bit DLL can't be loaded in 32-bit Python, for example, and SWIG wrappers also target a specific version of Python. – Mark Tolonen Mar 23 '18 at 01:25
  • I solved it... I was missing a C++ redistributable for 32 bit. I installed it an it worked ok. Thanks! – kostas May 31 '18 at 11:14
  • Could you give a few more details on how you fixed this? I have a Python 3.6.3 32-bit environment where I see this issue, and my Python 2.7.13 on the same system does not have any problems. – Fred S Jun 06 '18 at 17:33
  • @FredS Can you share some more info? In your case it might be a different problem. If you also use swig, check whether the `.pyd` file is compatible with python 3. [link](https://stackoverflow.com/questions/8846480/error-importing-a-pyd-file-as-a-python-module-from-a-pyo-file). Keep us posted! – kostas Jun 07 '18 at 08:01
  • Yeah I'm thinking maybe it's not possible to generate swig .pyd files that are compatible with python 3 and 2.7? – Fred S Jun 27 '18 at 23:04

0 Answers0