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
Related
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.
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.
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.
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.
I have a conda env in this directory in my mac
/anaconda/envs/dl
then I start my conda env by activate source dl
and when I start the jupyter it does not show the conda env dl, and only shows that its using python3 but not the conda env.
Notebook python3
And if I click terminal it shows this.
You need to install nb_conda, however, at the moment nb-conda cannot be directly installed with python3.6.
A way around that is to install it from conda-forge:
conda install -c conda-forge nb_conda
And also do not forget to install jupyter notebook on the new environment.
Install nb_conda , it should work.
To use jupyter notebook inside a virtual environment, ipykernal is required to be installed in your venv.
Inside your virtual environment:
pip install ipykernel
Then run the kernel "self-install" script:
python -m ipykernel install --user --name=my-virtualenv-name
Now, your new kernel has been installed.