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
Related
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.
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
I am running Ubuntu 18.04.3 LTS (4.15.0-58-generic kernel). I set up a virtual environment with
$ virtualenv venv
and activated it with
$ source venv/bin/activate
I installed a few packages
(venv) $ pip install numpy matplotlib
and then started a jupyter notebook
(venv) $ jupyter notebook
When I do a !pip list from inside a jupyter notebook I get a list of packages which are installed for the whole system and not for this environment. If I close the notebook and do a (venv) $ pip list everything is fine (i.e. I get a list of packages installed in the virtual environment).
So my question is, how do I force the Jupyter notebook to only use the packages from the virtual environment from which I started it?
Note that I installed some python packages previously with sudo pip install, is that causing my problems here?
You have to install a custom kernel
(venv) $ pip install ipykernel
(venv) $ ipython kernel install --user --name=projectname
After that you can start the notebook and choose the new kernel from the top menu -> kernel -> change kernel
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 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.