# Installing Python Packages in Jupyter Notebook - Right Way

**URL:** <https://openplanetary.discourse.group/t/installing-python-packages-in-jupyter-notebook-right-way/62>\
**Category:** Python\
**Created:** [May 23, 2019, 10:33am UTC](https://openplanetary.discourse.group/t/installing-python-packages-in-jupyter-notebook-right-way/62 "2019-05-23T10:33:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariodamore](https://yyz2.discourse-cdn.com/free1/user_avatar/openplanetary.discourse.group/mariodamore/32/13_2.png) [@mariodamore](https://openplanetary.discourse.group/u/mariodamore)\
**Post date:** [May 23, 2019, 10:33am UTC](https://openplanetary.discourse.group/t/installing-python-packages-in-jupyter-notebook-right-way/62/1 "2019-05-23T10:33:56Z")

</div>

I really suggest all the Jake’s blog and its book on Data Science ([freely available on his website](https://jakevdp.github.io/PythonDataScienceHandbook/)), it covers a lot of ground on python, visualisation, ML and how other general python cases. Jake is also a core contributor of “[scikit-learn: machine learning in Python](https://scikit-learn.org/stable/)”!  
“[Installing Python Packages from a Jupyter Notebook](https://jakevdp.github.io/blog/2017/12/05/installing-python-packages-from-jupyter/)” is helpful to have self-contained jupyter notebook with its dependencies packed in.  
This works better if you are running a jupyter notebook and its kernel is a python from a virtualenviroment. And you should definitively do this! Don’t pollute your system installation.  
In the link there is also a discussion on conda that I don’t (yet) use.  
Note the different python path on the commands output, they point to different python executables.

The gist of it is (quoting Jake’s blog here):

If you’re using the Jupyter notebook and want to install a package with `pip` , you similarly might be inclined to run pip directly in the shell:

```python
# DON'T DO THIS
!pip install numpy

```

```auto
Requirement already satisfied: numpy in 
/Users/jakevdp/anaconda/envs/python3.6/lib/python3.6/site-packages

```

For various reasons that I’ll outline more fully below, this **will not generally work** if you want to use these installed packages from the current notebook, though it may work in the simplest cases.

Here is a short snippet that should generally work:

```python
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy 

```

```auto
Requirement already satisfied: numpy in 
/Users/jakevdp/anaconda/lib/python3.6/site-packages

```

---

<div class="post-metadata">

**Author:** ![michaelaye](https://yyz2.discourse-cdn.com/free1/user_avatar/openplanetary.discourse.group/michaelaye/32/11_2.png) [@michaelaye](https://openplanetary.discourse.group/u/michaelaye)\
**Post date:** [May 23, 2019, 5:22pm UTC](https://openplanetary.discourse.group/t/installing-python-packages-in-jupyter-notebook-right-way/62/2 "2019-05-23T17:22:47Z")

</div>

Big fan of Jake here, too! 😉
