일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
- conda
- arXiver
- python
- Windows
- gfortran
- cython
- openmp
- Anaconda
- portforwarding
- tab space
- vi
- Visual Studio
- h5py
- HFS+
- jupyter
- GSL
- virtual
- mpi4py
- Matplotlib
- hyperref
- datascience
- HDF5
- cygwin
- SSH
- vim
- c++
- LaTeX
- intel compiler
- MAC
- polyglot
- Today
- Total
Astro Coke
[Conda] Add Virtual Environment to Jupyter Notebook 본문
Create Virtual Environment with Anaconda
Let’s have a look how to create an virtual environment with Anaconda. Anaconda is a Python (and R) distribution that has the goal to simplify package management and deployment for scientific computing. After the installation you can create the conda virtual environment with:
> conda create -n myenv
where myenv is the name of your new environment. If you want a specific Python version that is not your current version, you can type:
> conda create -n myenv python=3.7
The environment is then stored in the envs folder in your Anaconda directory. After you have created the enviroment, you can activate it by typing:
> source activate myenv
To check the environment, which is currently set:
> conda info -e
If you now run python, you’ll see that you are in your freshly created virtual environment. To deactivate the environment you can type conda deactivate and you can list all the available environments on your machine with conda env list. To remove an enviroment you can type:
> conda env remove -n myenv
After creating your environment, you can install the packages you need besides the one already installed by conda. You can find more information on how to manage conda environments in this user guide.
Add Virtual Environment to Jupyter Notebook
Jupyter Notebook makes sure that the IPython kernel is available, but you have to manually add a kernel with a different version of Python or a virtual environment. First, you need to activate your virtual environment. Next, install ipykernel which provides the IPython kernel for Jupyter:
> pip install --user ipykernel
Next you can add your virtual environment to Jupyter by typing:
python -m ipykernel install --user --name=myenv
> python -m ipykernel install --user --name=myenv
This should print the following:
Installed kernelspec myenv in /home/user/.local/share/jupyter/kernels/myenv
In this folder you will find a kernel.json file which should look the following way if you did everything correctly:
{
"argv": [
"/home/user/anaconda3/envs/myenv/bin/python",
"-m",
"ipykernel_launcher",
"-f", "{connection_file}" ],
"display_name": "myenv",
"language": "python"
}
Remove Virtual Environment from Jupyter Notebook
After you deleted your virtual environment, you’ll want to remove it also from Jupyter. Let’s first see which kernels are available. You can list them with:
> jupyter kernelspec list
This should return something like:
Available kernels:
myenv /home/user/.local/share/jupyter/kernels/myenv
python3 /usr/local/share/jupyter/kernels/python3
Now, to uninstall the kernel, you can type:
jupyter kernelspec uninstall myenv
> jupyter kernelspec uninstall myenv
'Computer Setup' 카테고리의 다른 글
[Latex] pdflatex occasionally conflicts with hyperlink breaking (0) | 2020.08.16 |
---|---|
[Windows] Python setup for Sub-Users (0) | 2020.07.29 |
[Conda] Create Virtual Environments for python with conda (0) | 2020.06.12 |
[Python] Setup mpi4py (intel compiled) in Cygwin Window (0) | 2020.02.03 |
[ImageMagick] resize pdf files (0) | 2019.12.16 |