[英]bash script to run jupyter notebook in virtualenv
To speed up launching projects I created a small bash script which does the following:为了加快启动项目,我创建了一个小的 bash 脚本,它执行以下操作:
#!/bin/bash
if [ "$1" == "k3" ]; then
project_path="tau-code/k3-analysis/"
fi
codepath="/media/peter/somedrive/code"
full_path="$codepath/$project_path"
# Go to directory of project
cd $full_path
# Start environment & notebook if available
pipenv shell
jupyter notebook --ip=0.0.0.0
It activates the environment, but does not run the jupyter
command.它激活环境,但不运行
jupyter
命令。 When I exit the environment I see the error:当我退出环境时,我看到了错误:
line 16: jupyter: command not found
I can manually type jupyter notebook --ip=0.0.0.0
in my newly created environment and that does work.我可以在我新创建的环境中手动输入
jupyter notebook --ip=0.0.0.0
并且确实有效。
What may be the problem?可能是什么问题?
pipenv shell
starts a new shell which must be deactivated by using exit
. pipenv shell
启动一个新的 shell ,必须使用exit
将其停用。 In your script any commands following the call to pipenv shell
are not executed in that new shell.在您的脚本中,调用
pipenv shell
之后的任何命令都不会在新的 shell 中执行。 Instead they are executed in the same bash shell after the virtual environment shell is closed.而是在虚拟环境 shell 关闭后在同一个 bash shell 中执行。 You should use
pipenv run jupyter notebook --ip=0.0.0.0
您应该使用
pipenv run jupyter notebook --ip=0.0.0.0
See pipenv documentation :请参阅pipenv 文档:
shell
will spawn a shell with the virtualenv activated.shell
将在激活 virtualenv 的情况下生成 shell。 This shell can be deactivated by usingexit
.这个 shell 可以使用
exit
停用。run
will run a given command from the virtualenv, with any arguments forwarded (eg$ pipenv run python
or$ pipenv run pip freeze
).run
将从 virtualenv 运行给定命令,并转发任何 arguments(例如$ pipenv run python
或$ pipenv run pip freeze
)。
Hi you need to add this嗨,你需要添加这个
pipenv run jupyter notebook
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.