有没有一种方法来使用 pipenv 与木星笔记本?

有没有一种方法来使用 pipenv 与木星笔记本?

或者更具体地说,使用原子交互/氢 Python 3内核?

46306 次浏览

Just tried the following with success.

In your project folder:

pipenv install ipykernel
pipenv shell

This will bring up a terminal in your virtualenv like this:

(my-virtualenv-name) bash-4.4$

In that shell do:

python -m ipykernel install --user --name=my-virtualenv-name

Launch jupyter notebook:

jupyter notebook

In your notebook, Kernel -> Change Kernel. Your kernel should now be an option.

Change Kernel Screenshot

Source: IPythonNotebookVirtualenvs

Luis' answer works perfectly for jupyter notebooks.

But for hydrogen/atom specifically the recipe is:

pipenv install ipykernel
pipenv shell

launch atom from within the pipenv shell

> atom

Should be good to go!

Install and start jupyter inside pipenv:

pipenv install jupyter
pipenv run jupyter notebook

Any other packages that are installed via pipenv (e.g. pipenv install numpy) will also be available to your jupyter notebook session.

My answer is based on previous answers, but I found one more step was necessary (pipenv install notebook). So in total:

Step 1. On terminal, first install both jupyter and (jupyter) notebook. In my experience, the latter had to be explicitly installed:

pipenv install jupyter notebook

Step 2. Install the Pipenv kernelspec for jupyter (modified from u-phoria's comment).

pipenv run python -m ipykernel install --user --name=`basename $VIRTUAL_ENV`

Now the following should work:

pipenv run jupyter notebook

Note: If in the Pipenv shell for the virtual environment, pipenv run can be removed from the above. If Pipenv is being forced to ignore virtual environments, the run commands should be run in the shell for the environment

For the original question of using Atom, it can then be run by this pipenv:

pipenv run atom