# Extensions upgrade to Python3

**URL:** https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074
**Category:** Development
**Tags:** extensions-manager
**Created:** [October 16, 2020, 9:23am UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074 "2020-10-16T09:23:17Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)
#### Post date: [October 16, 2020, 9:23am UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/1 "2020-10-16T09:23:17Z")

</div>

Hi all,

Our extension ([GeodesicSlicer](https://github.com/FredericBr/SlicerGeodesic)) does not work in the last version of Slicer (4.11.20200903) because it needs to be ported for python3. I have to do that in a couple of days (or may I have to wait the Slicer5?).  
But even if I upgraded it for Python 3, is it possible to keep a version compatible with the previous version of Slicer (and thus Python2, if yes, how to do that)?

Thanks,

Frederic

---

<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: [October 16, 2020, 2:42pm UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/2 "2020-10-16T14:42:07Z")

</div>

What seems to work best for most extensions is to create a separate branch for each Slicer major.minor release:

- create a `4.10` branch from your current master (if you want to make further fixes or improvements in this version, you can do that in this branch)
- update your s4ext file for SLicer-4.10 to use this branch (in [https://github.com/Slicer/ExtensionsIndex/blob/4.10/GeodesicSlicer.s4ext](https://github.com/Slicer/ExtensionsIndex/blob/4.10/GeodesicSlicer.s4ext), change `master` to `4.10`)
- make all the necessary changes `master` branch to make your extension work in the current Slicer version

See for example how it is done for MarkupsToModels:

- [https://github.com/SlicerIGT/SlicerMarkupsToModel/branches](https://github.com/SlicerIGT/SlicerMarkupsToModel/branches)
- [https://github.com/Slicer/ExtensionsIndex/blob/4.10/MarkupsToModel.s4ext#L10](https://github.com/Slicer/ExtensionsIndex/blob/4.10/MarkupsToModel.s4ext#L10)

---

<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: [October 16, 2020, 2:46pm UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/3 "2020-10-16T14:46:12Z")

</div>

Looking at the migration guide may also be helpful. See [https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide#Python\_2\_to\_Python\_3](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/MigrationGuide#Python_2_to_Python_3)

---

<div class="post-metadata">

### Author: ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)
#### Post date: [October 21, 2020, 1:42pm UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/4 "2020-10-21T13:42:53Z")

</div>

Thanks @lassoan and @jcfr for your valuable comments.

The first step is done, Now I have to make the changes to work with Python 3.

Best.

---

<div class="post-metadata">

### Author: ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)
#### Post date: [October 22, 2020, 2:10pm UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/5 "2020-10-22T14:10:16Z")

</div>

I allow myself another question, if you want I can create another post.

When I use your script @lassoan ( [**ExtractSkin.py**](https://gist.github.com/lassoan/1673b25d8e7913cbc245b4f09ed853f9#file-extractskin-py), I obtain the wrong orientation (cf. pic where the yellow nose is normally in anterior) of my model.

Do you now why?

 ![Sans titre](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/a/aaaf44bd62bef623ab7aff2ac03de1461a4b8d0f.png)

Thanks.

---

<div class="post-metadata">

### Author: ![Frederic](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/frederic/32/4907_2.png) [@Frederic](https://discourse.slicer.org/u/Frederic)
#### Post date: [October 23, 2020, 2:24pm UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/6 "2020-10-23T14:24:27Z")

</div>

I got it. It was a [coordinate problem](https://discourse.slicer.org/t/ras-to-lps-origin-shift/7075).  
For the next one with the same issue, you just have to place this code (here in python) when you create you object.stl:

`writer.SetHeader("Name of the output. SPACE=RAS")`

[GeodesicSlicer](https://github.com/FredericBr/SlicerGeodesic) is now ready for Slicer 4.11!

---

<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: [October 25, 2020, 1:58am UTC](https://discourse.slicer.org/t/extensions-upgrade-to-python3/14074/7 "2020-10-25T01:58:17Z")

</div>

Thanks for the update. I’ve updated the example script to export the mesh in a simpler way, by calling:

```python
slicer.vtkSlicerSegmentationsModuleLogic.ExportSegmentsClosedSurfaceRepresentationToFiles(
  "c:/tmp", segmentationNode, None, "STL")

```
