how to fix no module name tensorflow in jupyter notebook - tensorflow

I am facing the problem where tensorflow is not running in the jupyter notebook it is showing me
No module named tensorflow
But it is running ine anaconda prompt how to fix this

Personally I would try it this:
First create a new environment:
conda create -n test_tensor
Second we can activate that enviornment now that we created using the source command:
source activate test_tensor
Then we can install pip:
conda install pip
The we can installTensorFlow
pip install --upgrade tensorflow
These links could help also:
Trouble with TensorFlow in Jupyter Notebook
Running Tensorflow in Jupyter Notebook

Related

Error when installing TensorFlow through pip

I'm following the instructions from https://www.tensorflow.org/install/pip#python-version-support to install tensorflow. I've used tensorflow before but for some reason, it has just stopped working. I'm using VS Code.
First, I check that pip and python are compatible:
python3 --version
python3 -m pip --version
I have Python 3.10.8, with pip 22.3.1 so it should be compatible. Then, I create a conda environment and activate it:
conda create --name tf python=3.9
conda activate tf
However, now when I try
pip install tensorflow
I get the error
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
How can I fix this? I also tried things in the past like installing tensorflow through Conda, but I get errors when importing tensorflow there.
Could you please try again by opening anaconda cmd propmt and run below code:
conda create --name tf_new python=3.10
conda activate tf_new
then install tensorflow using:
pip install tensorflow
Now open the VS code by selecting the same created VirEnv tf_new from Anaconda navigator.
In VScode, Open a new jupyter notebook file and run the below code by selecting the tf_new (Conda VirEnv) in kernel(from top right) .
import tensorflow as tf
tf.__version__
Output:
'2.11.0'

install tensorflow from jupyter notebook

I'm trying to install tensorflow from Jupyter notbook. Any reason the blow seems to be hung up.
The code I used to install it is:
conda install -c conda-forge tensorflow
Create virtual environment for Tensorflow
#create virtual environment tf and install python
conda create -n tf python=3.9
#activate virtual env
activate tf
#install tensorflow
pip install tensorflow
#install Jupyter notebook
pip install jupyter
#Launch notebook
jupyter notebook
OR.
Jupyter notebook is available then just run !pip install tensorflow on jupyter notebook

Trying to import Tensor flow in my jupyter notebook but getting an error

screenshot of the error I'm getting:
Create a New Virtual Environment in Anaconda and Try installing the Latest Version of Tensorflow.
Steps are mentioned below:
conda create -n TF_Latest python=3.8 anaconda
conda activate TF_Latest
pip install tensorflow
Also, please find Anaconda Documentation for Installing Tensorflow, for more information.

How to access to tensorflow from Jupyter notebook?

I installed tensorflow 2.0 from source, following the official instructions: https://www.tensorflow.org/install/source
It works when I access from python console (Outside of tensorflow folder), I want to get access from Jupyter notebook.
I copied tensorflow's folder to:
/home/kati/anaconda3/pkgs/tensorflow
but still not working
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-d6579f534729> in <module>
----> 1 import tensorflow
ModuleNotFoundError: No module named 'tensorflow'
System Info
Ubuntu 18.04.3
jupyter core : 4.5.0
jupyter-notebook : 6.0.0
Here are the steps:
Download Anaconda
Create a virtual environment and activate it
Install K̵e̵r̵a̵s̵ ̵a̵n̵d̵ TensorFlow etc.
Launch Jupyter Notebook
Since you already have Jupyter Notebook, you will need to create an env variable, install tensorflow and keras. Commands are mentioned below:
update conda in your default environment
$ conda upgrade --all
create a new environment with conda
$ conda create -n [my-env-name] python=[python-version]
activate the environment you created
$ source activate [my-env-name]
install pip in the virtual environment
$ conda install pip
install Tensorflow CPU version
$ pip3 install --upgrade tensorflow # for python 3.*
install Keras (Note: please install TensorFlow first)
$ pip install Keras
remove an environment
$ conda env remove --name [my-env-name]
Install pip package and then you can just use "pip install [package name]" command to install any package easily.
Did you start running jupyter notebook from the virtual environment which you installed tensorflow?
Also you don't need to copy tensorflow to anaconda3 folder it's better to install by using pip or anconda navigator.
pip install tensorflow
Reference:
https://pypi.org/project/tensorflow/

Tensorflow version different in conda env & jupyter notebook

I created a conda env and installed tensorflow 1.4
pip install tensorflow==1.4
This installed, and from within the environment, when i type
import tensorflow as tf
tf.__version__
it prints '1.4.0'
Now, i open jupyter notebook from the same environment, and when i type the same in the notebook, it gives me 1.10.0
How is this possible? Jupyter notebook should take the same libraries within which it is running. How does it have a different version of tensorflow
And btw I'm concerned with this because i wanna use 1.4.0 in my notebook
These are the questions I ask myself in situations like this, and they usually resolve my issue:
Was the kernel of my notebook running while I pipped? Shut down and restart.
Are pip and conda sharing PATH, et cetera? I don't take it for granted that my pip is modifying my conda env. You can check with these commands.
Your conda env is created, but is it active? You list created envs with these, and you can activate/deactivate with these.
Besides checking all of these, where am I launching jupyter from? I like to install jupyter with a simply pip install jupyter and that could add jupyter to the command line globally. Anaconda navigator/command line reliably launches the jupyter that lives in your Anaconda distribution.
To add to Charles Landau:
You likely installed tensorflow in parallel with pip and with conda.
Within your env, just check with pip list tensorflow and conda list tensorflow. Most likely you will see two different versions.
To be consistent do:
pip unistall tensorflow to keep only one.