# Factory build of python extensions conflicting with each other

**URL:** <https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935>\
**Category:** Support\
**Created:** [February 12, 2022, 3:07pm UTC](https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935 "2022-02-12T15:07:57Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [February 12, 2022, 3:07pm UTC](https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935/1 "2022-02-12T15:07:57Z")

</div>

I noticed an issue occurring during the factory build of python extensions where an extension may be installing new python packages which results in Slicer core python packages having their installed version modified. This may be with general tools like `pip`, `setuptools`, etc.

When this happens if impacts all extensions built afterwards which have to use modified versions of these packages. This makes it difficult to make sure a Slicer extension that includes additional python packages is going to be successful because it can’t expect that it will be using the same versions of the tools like `pip` and `setuptools` from Slicer core.

For example SlicerRadiomics was built after SlicerJupyter. SlicerJupyter installs a large set of python packages ([CDash](https://slicer.cdash.org/viewBuildError.php?type=1&buildid=2588996)) where the build process says to install to a special location.

> <https://github.com/Slicer/SlicerJupyter/blob/4c69a34746a273290f977a9823c8171498da865f/SuperBuild/External_python-packages.cmake#L42-L68>

During the process it appears that `setuptools` is uninstalled but not reinstalled in the expected Slicer core location. This results in a SlicerRadiomics build error seemingly saying that there is no `setuptools` available to use ([CDash](https://slicer.cdash.org/viewBuildError.php?buildid=2589004))

I wonder if Slicer core external python projects should be re-run after each extension is built to make sure the extension is built against the expected versions in Slicer core. Or some other method to make sure that factory built extensions are not modifying the Slicer core build tree so that each subsequent factory built extension is built against the same version of the build tree.

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 12, 2022, 3:57pm UTC](https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935/2 "2022-02-12T15:57:23Z")

</div>

This is a really important point @jamesobutler, thanks for bringing it up. A clean solution could be to copy the Slicer tree to a fresh directory so that each extension is installed and tested independently.

---

<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:** [February 13, 2022, 2:13pm UTC](https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935/3 "2022-02-13T14:13:09Z")

</div>

When an extension is built then it may rely on all extension that it depends on (recursively), so if we save the state then it may need to be a stack where we can push the state of the folder and then pop that state (instead of always just resetting the original state).

This may not require entire folder copying because `pip` can store all package versions in a string and then restore that state.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [April 29, 2022, 8:34am UTC](https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935/4 "2022-04-29T08:34:47Z")

</div>

To follow-up on this, the SlicerJupyter extension has been updated to remove the use of `--force-reinstall`.

> <https://github.com/Slicer/SlicerJupyter/pull/71>
>
> This commit reverts use of \`--force-reinstall\` originally introduced in c59b08fa…9 (Fix python package installation).
> 
> The use of \`--force-reinstall\` led to removal of package like \`setuptools\` from the \`site-packages\` directory associated with the application and was causing the build of following extension (e.g SlicerRadiomics) to fail.
> 
> See https://discourse.slicer.org/t/factory-build-of-python-extensions-conflicting-with-each-other/21935
