# Python package installation

**URL:** <https://discourse.slicer.org/t/python-package-installation/19496>\
**Category:** Development\
**Created:** [September 3, 2021, 11:51am UTC](https://discourse.slicer.org/t/python-package-installation/19496 "2021-09-03T11:51:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 3, 2021, 11:51am UTC](https://discourse.slicer.org/t/python-package-installation/19496/1 "2021-09-03T11:51:11Z")

</div>

Hi everyone,  
Is there a way to install a python package in slicer’s python environment (using pip) but not during the runtime of Slicer. What would be the cleanest way to do it?  
Thanks for your advices,

Pierre

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [September 3, 2021, 2:05pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/2 "2021-09-03T14:05:27Z")

</div>

In the Slicer binary folder there is PythonSlicer.exe which you can use like you would a system python install python packages into slicer’s python environment. `PythonSlicer.exe -m pip install X`.

Are you asking how to do this not during runtime of Slicer because you are changing the version of a python package that is in Slicer core? If so, this could lead to some incompatibilities as Slicer is tested primarily on the specific versions included.

If you’re looking to install a python package as required by a module, but you don’t want to do it during Slicer run-time you could package the python package at time of building the extension. See [SlicerRadiomics](https://github.com/AIM-Harvard/SlicerRadiomics) of how they package `pyradiomics` with the extension.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 3, 2021, 3:23pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/3 "2021-09-03T15:23:54Z")

</div>

Hi James,  
Thank you for your input.  
The last paragraph, probably what we are looking for. For instance, how we can install scipy at building stage.

I will look at it !  
Cheers,

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [September 3, 2021, 4:56pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/4 "2021-09-03T16:56:42Z")

</div>

Using pip install to install scipy indicates you are likely wanting the whl file as provided by PyPI. Slicer already by default contains Scipy as you shouldn’t need to install it again. Is there something wrong with this already included version?

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 4, 2021, 8:13pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/5 "2021-09-04T20:13:46Z")

</div>

sorry, scipy was just for the example. I need to install weasypdf.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 5, 2021, 12:24am UTC](https://discourse.slicer.org/t/python-package-installation/19496/6 "2021-09-05T00:24:46Z")

</div>

> [@riep](#):
>
> I need to install weasypdf

There is no such package on PyPI. Are you sure this is the correct name?

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 5, 2021, 1:06pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/7 "2021-09-05T13:06:02Z")

</div>

Maybe documentation is not up-to-date but there is [First Steps — WeasyPrint 53.2 documentation](https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#linux)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 5, 2021, 8:21pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/8 "2021-09-05T20:21:24Z")

</div>

This (`weasyprint`) is a different package. You wrote you were trying to install the non-existing `weasypdf` package.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 6, 2021, 6:13am UTC](https://discourse.slicer.org/t/python-package-installation/19496/9 "2021-09-06T06:13:46Z")

</div>

😑 sorry about that… I will post my solution here.

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 6, 2021, 10:51am UTC](https://discourse.slicer.org/t/python-package-installation/19496/10 "2021-09-06T10:51:26Z")

</div>

Well, I am really struggling to understand Cmake and the way it could be done. Could you help me on that, please ?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [September 6, 2021, 12:45pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/11 "2021-09-06T12:45:05Z")

</div>

Would you like to bundle the Python package in an extension or in a custom Slicer application?

---

<div class="post-metadata">

**Author:** ![riep](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/riep/32/9933_2.png) [@riep](https://discourse.slicer.org/u/riep)\
**Post date:** [September 6, 2021, 2:56pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/12 "2021-09-06T14:56:12Z")

</div>

In a custom slicer application

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [September 6, 2021, 3:54pm UTC](https://discourse.slicer.org/t/python-package-installation/19496/13 "2021-09-06T15:54:24Z")

</div>

For a Slicer custom app you can use SlicerSalt as an example. See the following below how some python packages are installed as part of the superbuild process.

> <https://github.com/Kitware/SlicerSALT/blob/345f48977013b4cfa8a3c3f9240cb27bfb0ea77a/SuperBuild/External_python-mfsda-requirements.cmake>
