0

I have a virtual environment containing a package I need to test in a notebook.

I've got it working in the following manner:

> pip install ipykernel

> ipython kernel install --user --name=foo
Installed kernelspec foo in /Users/pi/Library/Jupyter/kernels/foo

> cat /Users/pi/Library/Jupyter/kernels/foo/kernel.json
{
 "argv": [
  "/usr/local/anaconda3/bin/python",
  "-m",
  "ipykernel_launcher",
  "-f",
  "{connection_file}"
 ],
 "display_name": "foo",
 "language": "python"
}

Now I edit the python path in that file to /path/to/my/virtualenv/bin/python.

Now I do jupyter notebook -> new -> foo, and create a test-cell with import MyPackage, and it works!

My question is: is there a proper way to do this?

(Useful link: https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/)

1 Answer 1

1

Personally, I would use pipenv.

First create a new folder and cd to it:

mkdir [name-of-my-python-env]
cd [name-of-my-python-env]

Now install the environment along with any additional packages you need:

pipenv install jupyter foo bar

Start the notebook server:

pipenv run jupyter notebook

If you need to add any new dependencies just pipenv install them and restart your server.

Sign up to request clarification or add additional context in comments.

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.