Tensorflow is not importing on jupyter notebook - python

I have installed tensorflow on my linux desktop and I have tried importing it in the terminal which worked. But when I tried the same thing on jupyter notebook, I am getting the error:
ModuleNotFoundError: No module named 'tensorflow'
To install tensorflow I have followed below steps:
conda create -n tensorflow_env python=3
source activate tensorflow_env
pip install tensorflow

Please install your conda environment using the below command in terminal
python -m ipykernel install --user --name tensorflow_env.
After installation,
1)reload your jupyter notebook.
2)In jupyter notebook, click on kernel->change kernel->tensorflow_env.
3)open new notebook with kernel "tensorflow_env"
4)Try importing tensorflow.

Related

"No module" after setting up jupyter kernel

I installed tensorflow using the official instructions:
conda create -n tf-gpu tensorflow-gpu
If I activate the kernel, I can see tensorflow is installed.
conda activate tf-gpu
python3 -c 'import tensorflow as tf; print(tf.__version__)'
It returns the following.
2022-03-24 01:21:50.006341: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.10.1
2.4.1
Now I want to have tf-gpu recognized as a kernel in jupyter notebook.
conda deactivate tf-gpu
python -m ipykernel install --user --name=tf-gpu
However, when I launch jupyter notebook
jupyter notebook
The created tf-gpu notebook does not work as expected.
import tensorflow
Returns the following error
ModuleNotFoundError: No module named 'tensorflow'
Why is the package not being recognized?
You need to make a new kernel for this env and select the kernel from jupyter notebook as follows:
conda activate env_name
pip install ipykernel --user
python -m ipykernel install --user --name env_name --display-name env_name
Then open the notebook >> click on kernel >> change kernel >> select the kernel.
Let us know if the issue still persists. Thanks!
Or you can also use ipython kernel instead of ipykernel after installation as shown below:
ipython kernel install --user --name env_name --display-name env_name

"No module named matplotlib" error in Jupiter Notebook

I open my anaconda virtual environment in this way (Linux)
source /home/sasha/anaconda3/bin/activate
conda activate gl-env (gl-env is my virtual environment)
pip3 install jupyter notebook
pip3 install matplotlib
pip3 install -U turicreate
jupyter notebook
After launching Jupiter, i see "No module named matplotlib" mistake, while turicreate is working normally.
How can i solve this problem?
You should not use pip with Anaconda. Use conda instead. So you commands should have been:
conda install jupitor notebook
conda install matplotlib
conda install turicreate
You can check conda for the -U option.

Tensorflow module not found by Jupyter notebook

Problem: Jupyter says "Module not found" when I try to import Tensorflow on Mac.
Background:
Virtualenv 16.7.9 installed & activated (venv)
Python 3.7.6 installed
PIP 19.3.1 installed
Tensorflow 2.1.0 installed using PIP as per official install instructions
At the command line, I can activate venv, start python3 then import tensorflow and display the tensorflow version correctly. But Tensorflow won't import from within Jupiter. And if I try to change the kernel within a Jupyter notebook, only Python3 is listed.
On other threads, people recommend using anaconda, but I've used PIP to install Tensorflow as recommended in the above link.
Any ideas?
Install a Jupyter Kernel
You need to install a kernel inside the env and then use Jupyter.
ipython kernel install --user --name=.venv
Then restart jupyter, click new, you should see .venv in your kernel list.

Problems installing tensorflow

I am using python notebooks using Anaconda for datascience and I'm trying to install tensor flow.
I have followed this tutorial:
https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html
and everything is fine. I can type import tensorflow as tf as written and I haven't errors. But when I return to python notebooks and I write import tensorflow as tf i continue to have this error:
No module named 'tensorflow'
How can I fix it?
You should have installed Jupiter notebook within your Conda environment.
conda activate <your-environment-name>
conda install -c anaconda jupyter
This solved the same problem for me.
Please follow the below steps to easily use your anaconda environment from jupyter notebook.
conda create -n myenv
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python(myenv)"
You can now switch the kernel in jupyter notebook and import all the packages that you have installed in your conda environment.

One conda environment automatically takes other's dependencies in jupyter notebook

I have two conda environments named 'myenv' and 'newenv' and i installed tensorflow in myenv but not in newenv and in both environment i installed ipykernel using:
pip install ipykernel
and then :
python -m ipykernel install --user --name name_env --display-name "Python (name_env)"
I did this in both environment so that now i have 3 kernels in my jupyter notebook named: Python(myenv),Python(newenv),Python3 .
But when changed to kernel newenv and try to import tensorflow and it imports however i haven't installed tensorflow in newenv but when i tried to import it through comand terminal of newenv it shows error 'No module named tensorflow'.
Then why it imports in jupyter notebook not in command terminal?
Please help me to solve this issue.

Categories