[IPython-dev] Using pip within notebooks

Matthias Bussonnier bussonniermatthias at gmail.com
Fri Oct 16 18:55:49 EDT 2015


Hi Jake, 

> On Oct 16, 2015, at 14:49, Jacob Vanderplas <jakevdp at cs.washington.edu> wrote:
> 
> Hi folks,
> One quick question – in previous IPython versions, I had often used ``!pip install`` commands from within the notebook to make sure packages are installed before importing them. I've noticed that in newer versions of the notebook this doesn't work – the kernel and the shell are not necessarily in sync: it seems that pip is by default tied to the python version which ran ``jupyter notebook``, rather than the Python version running the kernel.
> 
> Is there anything I can do to make pip work in the notebook again? Thanks!

a quick way would be the following: 

```
import sys
!{sys.executable} -m pip ...
```

or make use of some magics: 

https://pypi.python.org/pypi/pip_magic <https://pypi.python.org/pypi/pip_magic>   (don’t even need the ! anymore, just import it :-)


Won't work with conda though, unless you mess with the kernel spec to export PATH correctly to be in your envs,
So that any shelling out use conda executables executables instead of systems ones. Kind of a manual “source activate” step. 
I know that some people are working on Conda Kernels Launchers to automatize that.

Happy Coding. 

-- 
M

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20151016/b31ca5cb/attachment.html>


More information about the IPython-dev mailing list