# How to install python packages using jupyterlab?

**URL:** https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343
**Category:** Support
**Tags:** python, package, jupyter
**Created:** [January 6, 2022, 9:16am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343 "2022-01-06T09:16:36Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![user4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/user4/32/13172_2.png) [@user4](https://discourse.slicer.org/u/user4)
#### Post date: [January 6, 2022, 9:16am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343/1 "2022-01-06T09:16:36Z")

</div>

Hi all,I am using the Slicer 4.11 and I am stucked with installing packages.  
Here is the thing in detail:

I was trying to install some packages,say matplotlib in Slicer:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/4/d4ca52986a6e64b0c1f8a7fe837cba7c2b8831d3.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/8/485be21e163e3cff9561489cb74a892dedfb3009.png)

Also,I tried to install the package in Python Interactor:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/e/9e360b88c40c95f46c36fe44612c736f63b2104d.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/2/42dbadc74bba38df824bc9d3ba6042f9ee51362a.png)

Is there a way to manage the package installation quickly and easily?  
By the way I was using Anaconda to launch the jupyter and select the Slicer as a kernel.  
Thank you for any possible advice in advance.

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)
#### Post date: [January 6, 2022, 9:19am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343/2 "2022-01-06T09:19:19Z")

</div>

Normal install in jupyterlab

```auto
import sys
import subprocess

def installPackage(package):
    p = subprocess.run([sys.executable, "-m", "pip", "install", "-U", package], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    print(p.stdout.decode())

requirements = ["numpy", "scipy", "matplotlib", "chart_studio", "scikit-learn", "psutil", "openpyxl", "pandas", "pydicom","lmfit","numericalunits", "sqlalchemy"]
for requirement in requirements:
    installPackage(requirement)

```

Using Slicer kernel

```auto
from slicer.util import pip_install as installPackage

requirements = ["numpy", "scipy", "matplotlib", "chart_studio", "scikit-learn", "psutil", "openpyxl", "pandas", "pydicom","lmfit","numericalunits", "sqlalchemy"]
for requirement in requirements:
    installPackage(requirement)

```

---

<div class="post-metadata">

### Author: ![user4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/user4/32/13172_2.png) [@user4](https://discourse.slicer.org/u/user4)
#### Post date: [January 7, 2022, 3:21am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343/3 "2022-01-07T03:21:49Z")

</div>

Thank you Alex,  
This really works,so if I want to install other packages just add the package name in the requirements right?

---

<div class="post-metadata">

### Author: ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)
#### Post date: [January 7, 2022, 7:54am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343/4 "2022-01-07T07:54:25Z")

</div>

Normally yes, but you may also try `installPackage(requirement, "-U")` if something fails

---

<div class="post-metadata">

### Author: ![user4](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/user4/32/13172_2.png) [@user4](https://discourse.slicer.org/u/user4)
#### Post date: [January 7, 2022, 8:31am UTC](https://discourse.slicer.org/t/how-to-install-python-packages-using-jupyterlab/21343/5 "2022-01-07T08:31:51Z")

</div>

Okay,thank you Alex.
