I create a conda environment, activate install ipykernel, add it to jupyter kernelspec. This far, all works fine.
conda create -n MYENV python
conda activate MYENV
conda install ipykernel
python -m ipykernel install --user --name MYENV
conda deactivate
jupyter kernelspec list
MYENV /home/kara/.local/share/jupyter/kernels/MYENV
Then I launch the jupyter notebook on my base environment, and select the added kernel. However, while this kernel still runs, it uses the python from the base environment.
When I type !which python in the notebook, it returns "/home/kara/anaconda3/bin/python" while my python in that environment is actually in;
conda activate MYENV
which python
/home/kara/anaconda3/envs/MYENV/bin/python
How can I get jupyter to find the correct python? Now, when I install a package in that environment, jupyter cannot find it. I suspect it's because the package install to a different environment.
Related
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 anaconda python 2.7 installed on my windows and I recently created a new environment for python 3.5 (using conda create -n py35 python=3.5).
When I activate py35 and run jupyter notebook, it doesn't show py35 environment. It only has python root (py27).
How can I use this environment by jupyter ?
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.
See: pythonanywhere
You can install nb_conda and it will give you Conda environment and package access extension from within Jupyter. Inside your env you can use this command:
conda install nb_conda
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.
So I wanted to have the option of running python 3 or python 2 through my jupyter notebook.
So I followed Stack Overflow advice detailed here:
Using both Python 2.x and Python 3.x in IPython Notebook
Didn't work:
conda create -n py27 python=2.7 ipykernel
conda create -n py35 python=3.5 ipykernel
This did:
conda create -n py27 python=2.7
source activate py27
conda install notebook ipykernel
ipython kernel install --user`
`conda create -n py35 python=3.5
source activate py35
conda install notebook ipykernel
ipython kernel install --user
but now when I ran import numpy as np I get :
No module named numpy
I checked and I have 3 environments py35, py27 and root and I'm on root. And when I go to the terminal and pip install numpy, it tells me that it's already installed!
Is there anyway that I can use both kernels and have all my packages show. Or at least undo all this. Thanks!