[英]bash script to run jupyter notebook in virtualenv
為了加快啟動項目,我創建了一個小的 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
它激活環境,但不運行jupyter
命令。 當我退出環境時,我看到了錯誤:
line 16: jupyter: command not found
我可以在我新創建的環境中手動輸入jupyter notebook --ip=0.0.0.0
並且確實有效。
可能是什么問題?
pipenv shell
啟動一個新的 shell ,必須使用exit
將其停用。 在您的腳本中,調用pipenv shell
之后的任何命令都不會在新的 shell 中執行。 而是在虛擬環境 shell 關閉后在同一個 bash shell 中執行。 您應該使用pipenv run jupyter notebook --ip=0.0.0.0
請參閱pipenv 文檔:
shell
將在激活 virtualenv 的情況下生成 shell。 這個 shell 可以使用exit
停用。run
將從 virtualenv 運行給定命令,並轉發任何 arguments(例如$ pipenv run python
或$ pipenv run pip freeze
)。
嗨,你需要添加這個
pipenv run jupyter notebook
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.