[PYTHON] Reflect the virtual environment created with Miniconda in Jupyter notebook

1. Background

When my home PC broke down, I renewed my PC, and this time I installed a new Miniconda instead of the controversial Anaconda.

Created a virtual environment for posting articles to Qiita after a long time. I wanted to adapt the virtual environment created via miniconda to jupyter and verify it, but I was unexpectedly addicted to it ...

There were many articles that reflected Anaconda's virtual environment in jupyter, but in my case it was not possible to solve any of them because I am using Miniconda, so I will keep it as a record. (In conclusion, Miniconda was not relevant, but ...)

2. First, try based on the reference article

2-1. Creating a virtual environment

python


#sample_A virtual environment called env in python3.8.Created in 3(I think any version of python is fine)
conda create -n sample_env python=3.8.3

#sample created from base environment_Switch to env virtual environment
conda activate sample_env

2-2. Other work, confirmation

Introduction of jupyter_environment_kernels

python


#jupyter_environment_Installing kernels
pip install environment_kernels

Create jupyter_notebook_config.py

python


#~/.jupyter/jupyter_notebook_config.Configuration file is created in py
jupyter notebook --generate-config

Add the last line of the created jupyter_notebook_config.py as follows and save it * Miniconda

python


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

I check the operation, but ... it doesn't work. (You can now select something like ↓, but this is the base environment) 追加されたkernel

3. Solution and confirmation

I solved it by installing ipykernel while switching to the virtual environment.

python


#sample created from base environment_Switch to env virtual environment
conda activate sample_env

#Install ipykernel * You can also install jupyter
conda install notebook ipykernel

Restart jupyter from this state and check the current environment first. 追加されたkernel


Next, switch the virtual environment to sample_env with Kernel >> Change Kernel. 追加されたkernel


Finally, I checked the environment again and confirmed that the environment was switched. 追加されたkernel

4. Finally

The miso was to install ipykernel in the created virtual environment. The existence of the environment created by "! Conda info -e" could be confirmed without installing ipykernel, but the created virtual environment did not appear in "Change kernel" without installing ipykernel. Surprisingly, I'm spending time because of this ...

** (Addition) ** Also in the reference article There was a statement that "Jupyter must be installed even in the virtual environment to be created." .. I just overlooked this, but I think some people will stumble at the same place, so I will leave the article for the time being. (Miniconda's article is not even googled)


Reference article: Easy way to switch virtual environment created by Conda on Jupyter

https://gdcoder.com/how-to-create-and-add-a-conda-environment-as-jupyter-kernel/

Recommended Posts

Reflect the virtual environment created with Miniconda in Jupyter notebook
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
Try using conda virtual environment with Jupyter Notebook
Error running Jupyter Notebook in Anaconda virtual environment
Switch virtual environment with jupyter
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Machine learning with Jupyter Notebook in OCI Always Free environment (2019/12/17)
I want to use a virtual environment with jupyter notebook!
Reflect the virtual environment created by virtualenv or conda in the IntelliJ IDEA (PyCharm) project (memo)
I wanted to use jupyter notebook with docker in pip environment (opticspy)
How to easily switch the virtual environment created by Conda on Jupyter
Error "Entry point not found" when starting Jupyter Notebook in virtual environment
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
Start Django in a virtual environment with Pipenv
Browser specification of Jupyter Notebook in Windows environment
Create the strongest calculator environment with Sympy + Jupyter
Create a virtual environment with conda in Python
Fill the browser with the width of Jupyter Notebook
Work in a virtual environment with Python virtualenv.
If you want to enter the virtual environment with jupyter, nb_conda_kernels is recommended
virtual environment in python
Virtual environment with Python 3.6
Monitor the training model with TensorBord on Jupyter Notebook
Drawing a tree structure with D3.js in Jupyter Notebook
Try running python in a Django environment created with pipenv
How to build Anaconda virtual environment used in Azure Machine Learning and link with Jupyter
Using Graphviz with Jupyter Notebook
Display "Hello World" created in the local environment on the web
Use pip with Jupyter Notebook
About the garbled Japanese part of pandas-profiling in Jupyter notebook
Multiprocessing error in Jupyter Notebook
ML environment construction with Miniconda
Install Jupiter Notebook on Windows with pip in proxy environment
Use Cython with Jupyter Notebook
Play with Jupyter Notebook (IPython Notebook)
[SAP CP] Web API created with python in CF environment
After enabling the python virtual environment in the batch file, run the python file
[Anaconda] Activate the virtual environment
The usual way to add a Kernel with Jupyter Notebook
Connect the Jupyter Notebook kernel to Spyder with Jupytext enabled
Write charts in real time with Matplotlib on Jupyter notebook
I tried running the offline speech recognition system Julius with python in the Docker virtual environment
python3.8 venv environment jupyter notebook
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
What to do if pip --user returns an error in a virtual environment created with pyenv
How to batch start a python program created with Jupyter notebook
Web application created with Python + Flask (using VScode) # 1-Virtual environment construction-
Git management of Jupyter notebook (ipynb) differences in easy-to-read with JupyterLab
[Understanding in the figure] Management of Python virtual environment by Pipenv
How to use jupyter notebook without polluting your environment with Docker
Build a comfortable psychological experiment / analysis environment with PsychoPy + Jupyter Notebook
Debug settings in virtual environment when using Pipenv with VS Code
Learn machine learning anytime, anywhere in an on-demand Jupyter Notebook environment
Build jupyter notebook environment with Visual Studio Code (VS Code) Mac version
Activate Anaconda's virtual environment with PowerShell
Allow external connections with jupyter notebook
Formatting with autopep8 on Jupyter notebook
Build python virtual environment with virtualenv
Visualize decision trees with jupyter notebook
Easy Jupyter environment construction with Cloud9
Generate Jupyter notebook ".ipynb" in Python