3

To speed up launching projects I created a small bash script which does the following:

  • takes an argument (project name)
  • moves to the directory of that project
  • starts a virtual environment
  • starts a jupyter notebook
#!/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. 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.

What may be the problem?

1
  • 1
    can manally you check which jupyter in newly created environment ? and manually run env in newly created environment ? also same in your bash script after - pipenv shell pipenv shell env jupyter notebook --ip=0.0.0.0 i somewhere think its a path issue.. Commented Apr 20, 2020 at 7:43

2 Answers 2

4
+50

pipenv shell starts a new shell which must be deactivated by using exit. In your script any commands following the call to pipenv shell are not executed in that new shell. Instead they are executed in the same bash shell after the virtual environment shell is closed. You should use pipenv run jupyter notebook --ip=0.0.0.0

See pipenv documentation:

  • shell will spawn a shell with the virtualenv activated. This shell can be deactivated by using exit.
  • run will run a given command from the virtualenv, with any arguments forwarded (e.g. $ pipenv run python or $ pipenv run pip freeze).
Sign up to request clarification or add additional context in comments.

Comments

1

Hi you need to add this

pipenv run jupyter notebook

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.