简体   繁体   English

如何在 jupyter notebook 中使用 virtualenv

[英]How to use a virtualenv from inside a jupyter notebook

I am using a jupyter notebook, and inside this running jupyter notebook I want to use a virtualenv.我正在使用一个 jupyter 笔记本,这个正在运行的 jupyter 笔记本中,我想使用一个 virtualenv。

I was able to create and source(?) a virtualenv by using these commands通过使用这些命令,我能够创建和获取(?)一个 virtualenv

!virtualenv venv
!. venv/bin/activate

but it looks like python is still being used from the standard location但看起来python仍在标准位置使用

!which python
/opt/conda/bin/python

Is there any way to create and switch virtual environments from inside a running jupyter notebook?有什么方法可以从正在运行的jupyter notebook 中创建和切换虚拟环境?

After activating the venv激活venv

pip install ipykernel
ipython kernel install --user --name=venv
jupyter notebook

In jupyter Notebook you would be able to choose between venv and python x .在 jupyter Notebook 中,您可以在venvpython x之间进行选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM