Reputation: 11
I'm a beginner to python. I have installed python on my laptop and its version is Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 bit (Intel)] on win32. I'm trying to import an existing framework created by others and creating a new sample python file using the existing package. I wrote a simple line:
from machine_lib.pydblib import db
The pydblib is a file automatically generated from SWIG. The below code is grabbed from the SWIG file:
from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_pydblib')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_pydblib')
_pydblib = swig_import_helper()
The error is at the except block : return importlib.import_module('_pydblib')
which says :
ImportError: DLL load failed: The specified module could not be found in pycharm.
I have gone through the answers for the same error and nothing worked. How can I get rid of this error? I'm happy to share more info if required. Thanks in advance!
Upvotes: 1
Views: 4235
Reputation: 2989
Related note if you came here searching for "python", "import error" and "DLL load failed": in Python 3.8 DLL resolution under Windows has changed. Also see what's new in Python 3.8:
DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library. Note that Windows 7 users will need to ensure that Windows Update KB2533623 has been installed (this is also verified by the installer).
You can also use ProcessMonitor to check the name of DLLs Python is looking for.
Upvotes: 1