[IPython-dev] Using pip within notebooks

Aaron S. Meurer asmeurer at gmail.com
Fri Oct 16 21:30:47 EDT 2015


For conda you can use conda install -p {sys.prefix}. 

Aaron Meurer

> On Oct 16, 2015, at 5:55 PM, Matthias Bussonnier <bussonniermatthias at gmail.com> wrote:
> 
> 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   (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
> 
> _______________________________________________
> IPython-dev mailing list
> IPython-dev at scipy.org
> https://mail.scipy.org/mailman/listinfo/ipython-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20151016/53b3fc56/attachment.html>


More information about the IPython-dev mailing list