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

10

24

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!

Manno answered 21/9, 2017 at 21:10 Comment(0)
R
64

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.

Richart answered 2/10, 2018 at 1:34 Comment(6)
This worked for me. Note: For Windows Server (2016 Datacenter), you can skip path:\to\Anaconda3\Library\usr\binCanadianism
do I need to activate base every time I have to run notebook ?Supermundane
What if you want to change to an environment other than base?Quigley
The very purpose of Anaconda is to have different working environments. Therefore, running Jupyter inside the base environment only is not the solution.Spherical
All I did was add the directories to the PATH variable and it worked for me.Steeve
Thanks for your answer. I was missing the "activate base".Houlberg
G
31

In windows, active root(base) in command prompt first by

activate root

then

jupyter notebook
Gilcrest answered 28/11, 2018 at 9:46 Comment(2)
While this works, my question is "why do I have to activate an environment?" I didn't have to previouslyLithesome
@Lithesome I think its a new mandatory feature for more control environment. That's allGilcrest
S
7

I recently re-installed Anaconda to a new directory (from D: to C:). After that, opening and running PowerShell (in Windows 10) caused it to throw the same errors.

By following @picklu 's answer I was able to run it temporarily from the CMD (by running 'activate base' and then 'jupyter notebook'). Even 'activate root' worked instead of activate base. Also running it from conda prompt, anaconda navigator and the default shortcut for Jupyter Notebook worked. However, using these methods I wasn't able to start from the folder I had opened the PowerShell window in (by using Ctrl+Shift+ mouseRightCLick).

However, by following the second part of @picklu 's answer I was able to successfully change the system variable PATH from the old D: drive to the current C: .

I added the following:

  1. c:\users\USERNAME\anaconda3
  2. c:\users\USERNAME\anaconda3\scripts
  3. c:\users\USERNAME\anaconda3\library\bin
  4. c:\users\USERNAME\anaconda3\library\usr\bin

where c:\users\USERNAME\anaconda3 is the anaconda install location.

Spiry answered 16/1, 2019 at 3:53 Comment(3)
You seem to suggest that Picklu's answer works... this should be a comment, not a separate answer because you're not suggesting something newZacheryzack
Thanks! I tried everything , but adding all the path worked for me.Supermundane
This was my suspicion from the beginning. Thanks for spelling it out as a separate answer.Activate
S
5

If you have already added anaconda to PATH variable then you have to do the following

activate base jupyter kernelspec list python -m ipykernel install --user

It worked for me

Sadi answered 14/12, 2018 at 11:39 Comment(0)
K
3

I had the same problem when I import sklearn. I guess some packages needed to be upgraded. So I just ran (conda update --all) to upgrade all the packages, and it finally worked.

Kele answered 22/9, 2017 at 3:37 Comment(0)
R
1

I tried all the above solutions but didn't work for me until I installed the latest version of Microsoft Visual C++.

Randy answered 2/9, 2020 at 18:42 Comment(0)
S
1

In whichever virtual environment its breaking out, just activate the environment using:

conda activate <env-name>

and then re-install the notebook using:

pip install notebook

It was working fine for me in both Base as well as virtual environment until I upgraded from windows 10 to windows 11.

Selective answered 7/2, 2022 at 8:3 Comment(1)
Thanks Arun. This is simple. My environment works for 'base' but not for another.Kendre
S
1

Fixed this problen in 2 steps. This solution is for running a Jupyter Notebook

Open cmd or cmder and run as admin

  1. then type this command to uninstall pyzmq: pip uninstall pyzmq
  2. the re-download pyzmq by this command: pip install pyzmq

Then type jupyter notebook.

Suckle answered 6/2, 2023 at 20:58 Comment(0)
F
0

If we look at the Anaconda FAQ, we can find that it's not recommended to add Anaconda to the Windows PATH.

While it should work, it's not really easy and straightforward to manage all the needed paths manually. As an example, none of the answers here at the time of my writing has all the paths, which Anaconda adds on my machine. We can get the list using os module:

For Python 2:

Python 2.7.15 |Anaconda, Inc.| (default, Feb 21 2019, 11:55:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.environ['PATH']

For Python 3:

Python 3.7.2 (default, Feb 21 2019, 17:35:59) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print(os.environ['PATH'])

In my case, I have the following Anaconda paths in it:

C:\Anaconda;
C:\Anaconda\Library\mingw-w64\bin;
C:\Anaconda\Library\usr\bin;
C:\Anaconda\Library\bin;
C:\Anaconda\Scripts;
C:\Anaconda\bin;
C:\Anaconda\condabin;

And this is just for the base environment. If you have additional environments, there will be similar paths for each of them. Do you really want to add them all, update them, and make sure you haven't missed any if something is changed with new Anaconda release?

I doubt it. And the good news is that you don't have to. All the paths are configured for you automatically when you activate the environment.

It might only be usefull to add the Scripts folderto PATH, so that you can run activate without a full path. And then it might be handy to create a bunch of .bat/.cmd files for Python interpreters or Jupyter Notebook, which will simplify environment activation and allow you to do everything with one command.

For example, I have two .cmd files for Python 2 and Python 3 interpreter on my machine:

python.cmd:

@echo off
call activate
python %*

python3.cmd:

@echo off
call activate python37
python %*

A folder with these files is added to PATH, so when I run python or python3 command, the relevant conda environment is activated and the Python interpreter is started in the appropriate context. If you pass cmdline parameters to the interpreter, they are also forwarded correctly. Similar scripts can be cretated for Jupyter.

Frustule answered 12/3, 2019 at 0:44 Comment(0)
T
0

i sovled this issue by copy file C:\Anaconda3\Libary\bin\sqlite3.dll to C:\Anaconda3\Dlls

Trinia answered 6/11, 2020 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.