![为 jupyter-notebook 创建桌面启动器,但它位于 python 虚拟环境中](https://linux22.com/image/1013951/%E4%B8%BA%20jupyter-notebook%20%E5%88%9B%E5%BB%BA%E6%A1%8C%E9%9D%A2%E5%90%AF%E5%8A%A8%E5%99%A8%EF%BC%8C%E4%BD%86%E5%AE%83%E4%BD%8D%E4%BA%8E%20python%20%E8%99%9A%E6%8B%9F%E7%8E%AF%E5%A2%83%E4%B8%AD.png)
与许多其他开发人员一样,当我想要启动在我的存储库中运行的 jupyter 笔记本(使用 pipenv 虚拟环境)时,我总是遵循以下惯例:
cd /path/to/your/repository
pipenv shell (or conda activate, or other virtualenvs)
jupyter-notebook
但这太麻烦了。我希望有一个桌面应用程序可以自动完成这个任务,所以我遵循本指南。
我放入启动器的 shell 脚本中的代码正是我每天都会做的例行工作(与上述代码相同)。
但当我想
source jupyterlauncher.sh
,环境激活后终端就卡住了!就好像 ubuntu 在那一行之后创建了一个全新的终端。
有人知道这怎么实现吗?提前谢谢
答案1
该jupyter-notebook
命令附加到终端,您需要将其发送到后台,只需&
在行末尾添加一个与号,如下所示:
jupyter-notebook &
请记住,现在您需要从 Web 界面退出服务器。
答案2
可以通过创建 .desktop(如 jupyter.desktop)文件来实现。文件内容可以是这样的...
[Desktop Entry]
Version=1.0
Name=Jupyter Notebook
Exec=bash -c 'cd /path/to/repository;source /path/to/venv/bin/activate;jupyter-notebook'
Icon=utilities-terminal
Terminal=true
Type=Application
Categories=Application;
"/path/to/reository" should be where you want to open the jupyter notebook
"source /path/to/venv/bin/activate" is the virtual environment activation command. Change this according to your virtual environment