Import error: DLL load failed in Jupyter notebook but working in .py file

nth-attempt picture nth-attempt · Sep 21, 2017 · Viewed 30.5k times · Source

I installed BreakoutDetection the module in Anaconda environment. When I tried to import the module using import breakout_detection in jupyter notebook, I get the below error

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-18-96c0fdb15b96> in <module>()
----> 1 import breakout_detection

C:\Users\sgadiyar\AppData\Local\Continuum\Anaconda2\lib\site-packages\breakout_detection.py in <module>()
     15         except ImportError:
     16             return importlib.import_module('_breakout_detection')
---> 17     _breakout_detection = swig_import_helper()
     18     del swig_import_helper
     19 elif _swig_python_version_info >= (2, 6, 0):

C:\Users\sgadiyar\AppData\Local\Continuum\Anaconda2\lib\site-packages\breakout_detection.py in swig_import_helper()
     14             return importlib.import_module(mname)
     15         except ImportError:
---> 16             return importlib.import_module('_breakout_detection')
     17     _breakout_detection = swig_import_helper()
     18     del swig_import_helper

C:\Users\sgadiyar\AppData\Local\Continuum\Anaconda2\lib\importlib\__init__.pyc in import_module(name, package)
     35             level += 1
     36         name = _resolve_name(name[level:], package, level)
---> 37     __import__(name)
     38     return sys.modules[name]

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

I could import the same module in python shell

I looked at the system paths (print sys.path) and in both python shell and jupyter notebook. They both are the same. Executable path (print sys.executable) is also the same for the both.

Can someone help me out on the steps I should take to resolve this issue? Thanks!

Answer

picklu picture picklu · Oct 2, 2018

I encountered the same problem running Jupyter Notebook from PowerShell. Even though the question was asked a year back, I am answering it here to help those who encounter the same error recently. In my case, first, I activated the root environment activate base then I ran jupyter notebook and it worked just fine. Once you activate the base, you will notice that the prompt will change like this: (base) X:\Users\xxxxx\current-directory-name>.

  • Note that the command activate base will not work on Powershell. You have to switch to command prompt running cmd or you may try the whole thing on the command prompt instead of PowerShell.

  • If the required paths
    (path:\to\Anaconda3\;path:\to\Anaconda3\Scripts;path:\to\Anaconda3\Library\mingw-w64\bin;path:\to\Anaconda3\Library\usr\bin;path:\to\Anaconda3\Library\bin) are available to your PowerShell environment, then you don't need to activate the "base" environment.