12

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?

1
  • You could enter the venv with source $(pipenv --venv)/bin/activate. That would activate the virtual environment that you created with pipenv install without opening a new shell (which is what pipenv shell does). Then you need to use deactivate (not exit) to stop the venv. I hope that helps. Commented Mar 22, 2021 at 18:24

1 Answer 1

13

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
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the answer! just to clarify pipenv run will run any shell command i.e. pipenv run scrapy etc. not just python

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.