Difference between Jupyter and Terminal in the same Kernel


I’m trying to import tensorflow as ts in my script. While everything is fine in a Notebook, when I try to recreate the same script in a .py file the import returns the following, popular message:

ModuleNotFoundError: No module named 'tensorflow'

Note that both Jupyter and terminal are using the same virtual environment. In Notebook it’s picked as a Kernel and in terminal it’s activated with conda.

I was convinced the whole Kernel/env idea was about preventing exactly that kind of situations. Although I’m new to python so maybe I’m missing something basic.

Also, this might have something to do with that I’m using an M1 and macos, so I have the tensorflow-macos installed. But please consider there might be other reasons.


Make sure your pyenv installation doesn’t interfere with the conda environments. Pyenv can overrule which python installation is used even if the conda environment has picked another. In my case it was the reason. Jupyter Notebook wasn’t affected by pyenv. There are two solutions:

  1. Remove pyenv
  2. Make sure it is clear to you how both pyenv and conda are affecting your setup and correct it. Some considerations and suggestions are mentioned in this question: Installing anaconda with pyenv, unable to configure virtual environment

Answered By – wiktus239

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published