Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
308 views
in Technique[技术] by (71.8m points)

python - How to make conda virtual environments persistent and available for tools such as Jupyter Notebook?

When a conda environment is activated in a shell window, the environment is only active in that window (i.e. not persistent). So when I navigate to the project location in another window, the "root" virtual environment is active.

Am I missing something or is this the intended behaviour?

How to give tools such as Jupyter Notebook access to the created environment?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Register a (python) notebook kernel:

Let's suppose you have created a conda environment named jupyter-env35 with conda create -n jupyter-env35 python=3.5 and now want to use it in jupyter.

Installing and registering a python kernel in the environment will make it available over the graphical notebook interface.

To do so, first install the ipython kernel:

conda install -n jupyter-env35 ipykernel

Then activate the environment and register the kernel:

source activate jupyter-env35
ipython kernel install --user --name jupyter-env35

When you now fire up juypter, it will show jupyter-env35 as a kernel in the list of available kernels. If you select it, all packages installed into juypter-env35 will be available.

Unregister a notebook kernel:

If you want delete the kernel from the notebook interface, jupyter --data-dir, will print out jupyter's data directory.

Navigate to the printed folder, find the subfolder kernels and delete the folder with the name of your kernel (here jupyter-env35). After that the kernel will not show up in jupyter anymore.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...