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 ...)
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
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)
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.
Next, switch the virtual environment to sample_env with Kernel >> Change Kernel.
Finally, I checked the environment again and confirmed that the environment was switched.
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/