import tensorflow in Anaconda prompt - python

ModuleNotFoundError Traceback (most recent call last)
in ()
11 import numpy as np
12
---> 13 import tensorflow as tf
14
15
ModuleNotFoundError: No module named 'tensorflow'

I was looking for a similar issue (unable to import tensorflow in jupyter) and found that maybe most answers are outdated because now conda installs tf in its own environment.
The most useful thing I found is:
https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/
which explains in very few steps how to install tf or tf-gpu in its own environment.
Then my problem was that the jupyter notebook is in its own base environment, not in the tf-gpu environment. How to work with that from a jupyter notebook based on the base environment?
The solution comes from the very helpful answer from Nihal Sangeeth to this question
https://stackoverflow.com/questions/53004311/how-to-add-conda-environment-to-jupyter-lab
conda activate tf-gpu
(tf-gpu)$ conda install ipykernel
(tf-gpu)$ ipython kernel install --user --name=<any_name_you_like_for_kernel>
(tf-gpu)$ conda deactivate
Close and reopen your jupyter notebook.
Then in your jupyter notebook you will find the option, under "kernel" of "change kernel". Change kernel to your newly created kernel and you will be able to import tensorflow as tf and go on from there.
Hope it helps somebody

You can use following commands to import by Anaconda prompt:
conda install tensorflow
it will download all tensorflow environment setup.
then you can check any where:
import tensorflow

This might occur from several issues
Is tensorflow installed ?
pip install --upgrade tensorflow
Are you sure you're in the same conda enviroment which has tensorflow isntalled ?
conda env list
# conda environments:
deep-learning /Users/wassimseifeddine/anaconda/anaconda3/envs/deep-learning
root /Users/wassimseifeddine/anaconda/anaconda3
try switching between this environments source activate <env-name> and trying pip freeze to chech if tensorflow is installed.

Related

ModuleNotFoundError: No module named 'tensorflow_hub'

I followed instructions given in the TensorFlow website to install tensorflow_hub and installed it within a conda environment.
$ pip install "tensorflow>=2.0.0"
$ pip install --upgrade tensorflow-hub
I ran the above in anaconda prompt
But I'm still getting ModuleNotFoundError for 'tensorflow_hub'.
Any help here is appreciated. Thanks in advance
First thing
Check whether you have installed tensorflow_hub within that environment
conda list
If you can not find it there, maybe you have been installing it to another environment which does not matter, just install it again here.
pip install tensorflow_hub
You have probably done that so most likely you are using another kernel within your jupyter notebook, so either go to the environment of that kernel and install your package there. Or the preferred way, install your current environment yourenvironment as a new kernel and use that one in your jupyter notebook
python -m ipykernel install --user --name=yourenvironment
Now start your jupyter notebook and enjoy your package

Anaconda: Installing opencv in tensorflow environment

in Anaconda3 (python3.7) I made an Tensorflow environment named tf. Now I tried to install OpenCv into this environment. I tried several:
conda install --name tf opencv
conda install --name tf -c conda-forge opencv
I tried also inside the tf folder:
pip install opencv-python
all runs and installed something. But when I try to run my code the error appears that it couldn't find cv2.
I import it with
import cv2 as cv.
I run the code through Conda in Visual Studio Code. Ans I selcted the Interpreter Path Python3.7.6 64-bit('tf':conda)
The installation of numpy and matplotlib into this environment worked.
Does anyone know what I've done wrong? Or how I can combine these two, OpenCV and Tensorflow, through anaconda?
Thanks a lot
Use following commands
conda create -n tf tensorflow
conda activate tf
Then use
pip install opencv-python

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.

No module found error for every conda package in anaconda jupyter notebook

After installing the latest scikit-learn version (19) using conda in Anaconda Jupyter, all packages are showing ModuleNotFoundError - scikit learn, numpy, matplotlib, etc. This is happening for all conda packages. After uninstalling and reinstallling, I have the same problem.
My kernel specs :
sana#skb-linux:~$ . activate my_env
(my_env) sana#skb-linux:~$ jupyter kernelspec list
Available kernels:
python3 /home/sana/anaconda3/envs/my_env/share/jupyter/kernels/python3
My code:
# scipy
import scipy
print('scipy: %s' % scipy.__version__)
Result:
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-73263c49dde4> in <module>()
1 # scipy
----> 2 import scipy
3 print('scipy: %s' % scipy.__version__)
ModuleNotFoundError: No module named 'scipy'
You can check for the install packages by typing !conda list in the notebook and check for scikit-learn package is there or not.
If it's not present then you can install it by !pip install scikit-learn or !conda install -c anaconda scikit-learn
later try import sklearn it should work!.
There is a useful source here, including how to update or upgrade packages..
final solution: first need activate the environment you are working and install conda package in that particular environment using conda install and do need not to install outside of your environment
sana#skb-linux:~$ . activate my_env
(my_env) sana#skb-linux:~$ conda install scikit-learn
Solving environment: done
so the sklearn package is installed in your particular environment(in my case its installed my_env)
I encountered the same issue on installing jupyter through conda, tried a lot of things, didn't work out. Finally, I remove it and re-installed it, worked fine this time, lol!!

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