The installation process of Anaconda will not be repeated. Installing Anaconda will install Jupyter Notebook by the way. This article mainly records how to use Anaconda to create a virtual environment and how to use the created environment in jupyter Notebook.
- Create a virtual environment
conda create -n 虚拟环境名 python=版本
- Activate the virtual environment
activate 虚拟环境名
- Install ipykernel in the virtual environment (in the corresponding virtual environment)
pip install ipykernel
- Use ipykernel to generate the kernel of the virtual environment (in the corresponding virtual environment)
python -m ipykernel install --user --name 虚拟环境名
- Exit the virtual environment and reopen Jupyter Notebook in the base environment, and you will find that there is already a virtual environment kernel to choose from
- Exit the virtual environment
conda deactivate
- Open Jupter Notebook
jupyter notebook
The jupter notebook command can be used directly in the base environment or in a virtual environment. If you use it in a virtual environment, you need to exit the virtual environment and re-enter after the installation is complete.