Search code examples
bashshelljupyter-notebookpipenv

bash script starting new shell and continuing to run commands


I'm a complete noob to writing bash scripts. I'm trying to do the following:

#!/bin/bash

mkdir New_Project
cd New_Project
pipenv install ipykernel
pipenv shell
python -m ipykernel install --user --name==new-virtual-env
jupyter notebook

The problem I'm having is that after it executes pipenv shell, it starts the new shell and then doesn't execute the last two commands. When I exit the new shell it then tries to execute the remaining lines. Is there any way to get a script to run all of these commands from start to finish?


Solution

  • As per the manual :

    shell will spawn a shell with the virtualenv activated.

    which is not what you need. Instead use run :

    run will run a given command from the virtualenv, with any arguments forwarded (e.g. $ pipenv run python).

    In your case, something like

    pipenv run python -m ipykernel install --user --name==new-virtual-env