Python – Can’t access anaconda packages in jupyter notebooks

Can’t access anaconda packages in jupyter notebooks… here is a solution to the problem.

Can’t access anaconda packages in jupyter notebooks

EDIT: I found the answer. I have changed my default python to the anaconda version in my PATH but forgot to restart. After restarting, it worked. The default python was changed in CMD before rebooting, but not in my IDE or Jupyter.

If I run CMD and enter python, it returns the default python.

Python 3.6.4 | Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Here I can import anaconda packages, like this one.

>>> import statsmodels.api as sm
>>> sm
<module 'statsmodels.api' from 'C:\\Users\\mjpvanzuijlen\\Anaconda3\\lib\\site-packages\\statsmodels\\'>

In the jupyter notebook kernel, I can’t import any anaconda packages.

I made

a new notebook and chose the default Python3 kernel or the anaconda kernel I made. For both options, I get the following error.

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-085740203b77> in <module>()
----> 1 import statsmodels.api as sm

ModuleNotFoundError: No module named 'statsmodels'

Running Jupyter kernelspec list returns the two cores available to me.

C:\Users\mjpvanzuijlen>jupyter kernelspec list
Available kernels:
  python3     c:\users\mjpvanzuijlen\lib\site-packages\ipykernel\resources
  anaconda    c:\users\mjpvanzuijlen\share\jupyter\kernels\anaconda

where ...\kernels\anaconda\ contains the following kernel.json.

 "display_name": "anaconda",
 "argv": [
 "language": "python"

How do I run anaconda packages in a jupyter notebook?


It looks like you have multiple Python installed. You can use to

check which path the Python executable is running on

import sys

One possible culprit is that you installed an older version of Python with Jupyter somewhere in c:\users\mjpvanzuijlen\lib\. This in itself is not a big deal, however, you may also have an entry in your system’s PATH that contains the jupyter.exe file from an older Python installation.

Check that c:\users\mjpvanzuijlen\scripts\ is in your system path. If so, you can remove it from the PATH variable, or you can try uninstalling the previous Python installation.

Related Problems and Solutions