andrewssobral / bgslibrary

A C++ Background Subtraction Library with wrappers for Python, MATLAB, Java and GUI on QT
MIT License
2.2k stars 740 forks source link

import bgs ImportError: DLL load failed: Dynamic Link Library (DLL) initialization routine failed #161

Open limeflavour opened 5 years ago

limeflavour commented 5 years ago

I have bgs.cp36-win_amd64.pyd and libbgslibrary_core.dll, and I've added them to environment variables, but when i import bgs to my project , ImportError: DLL load failed: Dynamic Link Library (DLL) initialization routine failed

System information

Desktop

andrewssobral commented 5 years ago

Hi @limeflavour , Thanks for reporting the issue. Usually this issue is related to the Python Path that is not finding both bgs.cp36-win_amd64.pyd and libbgslibrary_core.dll as you can see here: https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-so-it-finds-my-modules-packages

Another way is to do :

python setup.py install
or
pip install .

or:

# follow https://github.com/andrewssobral/bgslibrary/wiki/Wrapper:-Python
# by adding the following CMake parameters:
cmake -DBGS_CORE_STATIC=ON -DBGS_PYTHON_SUPPORT=ON -DBGS_PYTHON_ONLY=ON 
linehammer commented 4 years ago

PYTHONPATH is an environment variable which you can set to add additional directories that Python should add to the sys.path directory list. For most installations, you should not set these variables since they are not needed for Python to execute normal programs because Python knows where to find its standard library. PYTHONPATH is used to assist in import module lookup. So when you import modules in your Python scripts, PYTHONPATH is also looked into to check which directories might contain the imported module

mitesh741 commented 1 year ago

Double click on bgslibrary.exe

It will show library name that could not be loaded.

Just load it from the python using ctypes.

cdll.LoadLirbary(full path to lib)

In my case it was opencv_world3418.dll where 3418 is the version it could be different in your case.