Problems installing tensorflow - python

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.

Related

How to resolve module not found error in JupyterNotebook for tensorflow?

I have created the tensorflow environment using the following set of commands:
conda create --name py3-TF2.0 python = 3
conda activate py3-TF2.0
conda install tensorflow
pip install -upgrade tensorflow
pip install ipykernel
Try these steps to install Tensorflow using Conda
#create virtual environmenttf2.0 using conda
conda create --name tf2.0 python=3
#Activate the env
conda activate tf2.0
#Install Tensorflow
tf2.0$pip install tensorflow
tf2.0$python
#Verify the Tensorflow installation before launching any of the IDE
>>import tensorflow as tf
>>tf.__version__
#Launch the jupyter notebook
tf2.0$conda install jupyter
tf2.0$jupyter notebook
What you can do is run the jupyter notebook and try installing tensorflow from there.
In a jupyter notebook cell type in:
!pip install tensorflow==2.0.0
(dont miss the ! sign before)
To test:
import tensorflow as tf
tf.__version__

ModuleNotFoundError in jupyter notebook when importing a module after conda install

I'm trying to use conda to set up one of my projects. I installed openCV by conda install -c conda-forge opencv. When I run conda list, I can see openCV in the list. Running python -i and then import cv2 works, but when I open up Jupyter Notebook and navigate to that folder (I have to do it this way because running jupyter notebook in the directory also pulls up an error), and open up a notebook which imports cv2, I get an error. Why is this happening, and how would I solve it? Any kind of help will be greatly appreciated.
So as I said before, I wasn't able to start Jupyter Notebook from the command line, I had to start it from the start menu and navigate to my folder. Because of that, my notebook wasn't working in the conda environment that I created. I fixed that by running python -m ipykernal install --user --name <env_name> --display-name "<display_name>". I had to conda install ipykernel. It works now. Thanks for the other answers.
Usually that indicates that the notebook is running with a different Python or in a different environment from Python in the command prompt. Check sys.executable to see which Python it's running in, and sys.path to see where it's looking for imports
Everybody says that pip installing from notebook is not the best practice, but maybe for a fast try it would do the thing:
# Install a conda package in the current Jupyter kernel
import sys
!conda install --yes --prefix {sys.prefix} packagename
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install packagename
I used it from Install python packages on Jupyter Notebook and it worked for me.
Step 1: Activate environment before running
conda activate <environment-name>
Step 2: Install ipykernel
conda install -c anaconda ipykernel
Step 3: Add the conda environment to ipykernel
ipython kernel install --name <environment-name> --user
Step 4: Install your package
conda install -c conda-forge opencv
References:
How to add your Conda environment to your jupyter notebook in just 4 steps
Conda environments not showing up in Jupyter Notebook

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.

Tensorflow is not importing on jupyter notebook

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.

Installing a package in Conda environment, but only works in Python not iPython?

I am using an Ubuntu docker image. I've installed Anaconda on it with no issues. I'm not trying to install tensorflow, using the directions on the tensorflow website:
conda create --name tensorflow python=3.5
source activate tensorflow
<tensorflow> conda install -c conda-forge tensorflow
It installs with no errors. However, when I import in iPython, it tells me there is no module tensorflow. But if I import when in Python, it works fine.
What's going on and how do I fix it?
You have to install IPython in the conda environment
source activate tensorflow
conda install ipython
I went through the same thing. We are installing tensorflow in different conda environment. So It may not consist of all the packages. I needed to install jupyter notebook separately in order to work.

Categories