使用特定的virtualenv在Jupyter Notebook中执行Python脚本

使用特定的virtualenv在Jupyter Notebook中执行Python脚本,第1张

使用特定的virtualenv在Jupyter Notebook中执行Python脚本

这是对我有用的内容(非

conda
python):(
MacOS,python的brew版本。如果您使用的是系统python,则可能(需要
sudo
)在每个命令前加上)

首先激活virtualenv

如果重新开始,那么,例如,您可以使用virtualenvwrapper

$pip install virtualenvwrapper$mkvirtualenv -p python2 py2env $workon py2env# This will activate virtualenv(py2env)$# Then install jupyter within the active virtualenv(py2env)$ pip install jupyter# jupyter comes with ipykernel, but somehow you manage to get an error due to ipykernel, then for reference ipykernel package can be installed using:(py2env)$ pip install ipykernel

接下来,设置内核

(py2env)$ python -m ipykernel install --user --name py2env --display-name "Python2 (py2env)"

然后启动jupyter笔记本(此步骤无需激活venv)

(py2env)$ jupyter notebook# or#$ jupyter notebook

在jupyter笔记本下拉菜单中:

Kernel >> Change Kernel >> <list of kernels>
您应该看到
Python2(py2env)
内核

这也使识别内核的python版本变得容易,并且可以并行维护任一版本。

这是详细文档的链接
http://ipython.readthedocs.io/en/stable/install/kernel_install.html



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5644464.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存