From f55737c650a65c0a50d316d04f1acbe81bb88ba8 Mon Sep 17 00:00:00 2001 From: Joseph Lizier Date: Wed, 26 Jul 2023 15:02:58 +1000 Subject: [PATCH] Further refinements to python environment start code --- demos/python/start_env.sh | 4 +++- demos/python/start_jupyter_env.sh | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/demos/python/start_env.sh b/demos/python/start_env.sh index 498add5..95a0903 100755 --- a/demos/python/start_env.sh +++ b/demos/python/start_env.sh @@ -26,7 +26,9 @@ folder=jpype_env source $folder/bin/activate if [ $? -ne 0 ]; then echo "Virtual environment unable to be activated" >&2 - return 3 # Need return instead of exit since we're running via source + # Try return first in case this script was sourced. + return 3 2>/dev/null + exit 3 else echo "Python environment from $folder started and activated." fi diff --git a/demos/python/start_jupyter_env.sh b/demos/python/start_jupyter_env.sh index f902a9d..c30a279 100755 --- a/demos/python/start_jupyter_env.sh +++ b/demos/python/start_jupyter_env.sh @@ -20,9 +20,21 @@ # Start the python environment (stored in folder $folder) with jpype1, numpy and others installed # and then launch jupyter -source start_env.sh +# Name of folder to use and python commands +folder=jpype_env -echo "Started virtual environment, now starting jupyter ..." +# enter the environment +source $folder/bin/activate + +if [[ "$VIRTUAL_ENV" != "" ]] +then + echo "Started virtual environment, now starting jupyter ..." +else + echo "Virtual environment not started, exiting" + # Try return first in case this script was sourced. + return 1 2>/dev/null + exit 1 +fi cd ../.. jupyter notebook