How to easily switch the virtual environment created by Conda on Jupyter

Recently, I've been touching Python, but I've been struggling a little because there are too many new and old methods and various information on the net just to build the environment.

I made it using Conda, which seemed to be the best for building a virtual environment in Python, but when I tried to use it with Jupyter, which is popular recently, I was addicted to it because I could not switch the kernel of the virtual environment well. , I will leave a memorandum about how to do it.

If all goes well, you'll be able to instantly switch between development environments from Jupiter's [Kernel]-> [Change kernel] as shown below, which is quite convenient! !! image

Assumption:

Conda and Jupyter installed

** Create an environment where numpy works with conda **

$ conda create -n numpyenv python=3.5 numpy jupyter

It is necessary to install jupyter even for the virtual environment to be created.

** Check the created virtual environment **

$ conda info -e
Using Anaconda Cloud api site https://api.anaconda.org
# conda environments:
#
numpyenv                 /Users/username/anaconda/envs/numpyenv
opencvenv                /Users/username/anaconda/envs/opencvenv
py35                     /Users/username/anaconda/envs/py35
root                  *  /Users/username/anaconda

You can see that an environment called numpyenv has been created.

** Install jupyter_environment_kernels **

A package for switching kernels is provided on Jupyter, so install it.

$ pip install environment_kernels

** Jupyter configuration file generation **

$ jupyter notebook --generate-config

Probably ~/.jupyter/jupyter_notebook_config.py I think that the setting file called is generated.

** Addition of settings to automatically load Conda environment **

Add the following to ~ / .jupyter / jupyter_notebook_config.py. ** (Note: may be old) **

c.NotebookApp.kernel_spec_manager_class = 'environment_kernels.EnvironmentKernelSpecManager'
c.EnvironmentKernelSpecManager.env_dirs=['/Users/username/anaconda/envs/']

** (* Addition: 2016/12/09) ** As you mentioned in the comments, in Latest version, it seems that only the following line is all right.

c.EnvironmentKernelSpecManager.conda_env_dirs = [ '/Users/username/anaconda/envs/' ]

For conda_env_dirs, check the path where the virtual environment is generated with conda info -e etc. and set it appropriately.

** Operation check **

$ jupyter notebook

When you start Jupyter, you can see that you can safely select a new kernel called numpyenv. image

reference: [Python] Create a virtual environment with Anaconda Cadair/jupyter_environment_kernels Jupyter Notebook and Conda

Recommended Posts

How to easily switch the virtual environment created by Conda on Jupyter
Execution environment on the Web by "Project Jupyter"
How to easily create an environment where python code runs on Jupyter without polluting the local environment
Switch virtual environment with jupyter
A memo on how to easily prepare a Linux exercise environment
How to switch the configuration file to be read by Python
How to build a new python virtual environment on Ubuntu
Reflect the virtual environment created with Miniconda in Jupyter notebook
A note on how to load a virtual environment in PyCharm
Reflect the virtual environment created by virtualenv or conda in the IntelliJ IDEA (PyCharm) project (memo)
How to use Jupyter on the front end of supercomputer ITO
Automatically switch virtual environment with conda + direnv
How to switch mouse operations on CentOS
Introducing keras on virtual environment (pyenv: anaconda) on server by conda (tensorflow backend)
Try to build python and anaconda environment on Mac (by pyenv, conda)
How to share a virtual environment [About requirements.txt]
How to create a Python virtual environment (venv)
[Latest] How to build Java environment on Ubuntu
How to make multiple kernels selectable on Jupyter
Try using conda virtual environment with Jupyter Notebook
How to erase the characters output by Python
How to build Java environment on Ubuntu (Linux)
If you want to enter the virtual environment with jupyter, nb_conda_kernels is recommended
How to avoid the cut-off label of the graph created by the plot module using matplotlib
How to create a Python 3.6.0 environment by putting pyenv on Amazon Linux and Ubuntu
Think about how to program Python on the iPad
How to put Takoyaki Oishikunaru on the segment tree
How to build a Django (python) environment on docker
How to instantly launch Jupyter Notebook from the terminal
How to check the Java version used by Maven
How to use jupyter lab in Windows 10 local environment
How to enjoy Python on Android !! Programming on the go !!
How to build a Python environment on amazon linux 2
How to view progress bar on Jupyter Notebook to see progress
How to unprefix the DB name used by pytest-django
How to build a Python virtual execution environment using Visual Studio Code and pipenv on a Windows machine (also Jupyter notebook)
How to virtual host
How to build Anaconda virtual environment used in Azure Machine Learning and link with Jupyter
How to change the MAC address of an automatically created virtual NIC to be event driven
How to run Python on Windows without polluting the environment as much as possible (Scoop edition)
How to manage Python minor version (build virtual environment) on Windows (without Pyenv or WSL)
How to easily draw the structure of a neural network on Google Colaboratory using "convnet-drawer"
Switch the setting value of setting.py according to the development environment
Memo to get the value on the html-javascript side with jupyter
Display "Hello World" created in the local environment on the web
How to test the attributes added by add_request_method of pyramid
[Hyperledger Iroha] Notes on how to use the Python SDK
How to use VS Code in venv environment on windows
How to deploy the easiest python textbook pybot on Heroku
Move what you installed with pip to the conda environment
How to develop in a virtual environment of Python [Memo]
I want to use a virtual environment with jupyter notebook!
How to see the contents of the Jupyter notebook ipynb file
How to get into the python development environment with Vagrant
Notes on how to use marshmallow in the schema library
How to print characters to the console before booting on ARM
Overview of Python virtual environment and how to create it
How to touch Jupyter Notebook without polluting the environment other than Pythonista, or how to touch Ruby with Jupyter Notebook without polluting the environment other than Rubyist
How to quickly create a machine learning environment using Jupyter Notebook on macOS Sierra with anaconda
How to use the generator
How to change Jupyter layout