# Python 3.11 Upgrade

**URL:** <https://discourse.slicer.org/t/python-3-11-upgrade/36235>\
**Category:** Development\
**Tags:** python\
**Created:** [May 17, 2024, 5:18pm UTC](https://discourse.slicer.org/t/python-3-11-upgrade/36235 "2024-05-17T17:18:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukepolson](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lukepolson/32/76573_2.png) [@lukepolson](https://discourse.slicer.org/u/lukepolson)\
**Post date:** [May 17, 2024, 5:18pm UTC](https://discourse.slicer.org/t/python-3-11-upgrade/36235/1 "2024-05-17T17:18:50Z")

</div>

Hi all,

We’re currently in the process of developing a tomographic reconstruction extension for 3D slicer (currently SPECT, we hope to build others for PET/CT soon as well). Our extension relies on PyTomography, which itself requires python 3.11; as such, this is a feature request to upgrade the python version of 3D Slicer to 3.11 🙂

---

<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:** [May 17, 2024, 8:34pm UTC](https://discourse.slicer.org/t/python-3-11-upgrade/36235/2 "2024-05-17T20:34:56Z")

</div>

Upgrading the Slicer python version from 3.9 to something newer is something currently being tracked at:

> <https://github.com/Slicer/Slicer/issues/7060>
>
> \## Is your feature request related to a problem? Please describe.
> 
> As I learne…d while working on #7046, the latest versions of python packages such as \`numpy\` and \`scipy\` now have a python minimum of 3.9 which is the version currently used by Slicer (3.9.10). Per \[NEP29 drop schedule\](https://numpy.org/neps/nep-0029-deprecation\_policy.html#drop-schedule), Python 3.9 support will begin to be dropped by major python packages beginning April 5th, 2024. However, NEP29 has now been superseded by \[SPEC 0\](https://scientific-python.org/specs/spec-0000/) where the \[drop schedule\](https://scientific-python.org/specs/spec-0000/#drop-schedule) states to drop Python 3.9 support in new releases starting in 2023 Q4 (marking the end of 3 years of support). Writing up this issue is to stay ahead of the deprecation curve so that Slicer does not get into a situation of not being able to use the latest versions of major python packages.
> 
> \## To answer the question: Is the newer version of Python supported by the open source community?
> When Slicer was updated from 3.6.7 to 3.9.10 in https://github.com/Slicer/Slicer/commit/34e48e8aef5dad19ec8a955d6f48a1940846e3f3:
> It was January 25th, 2022 and the "\[python readiness\](https://pyreadiness.org/)" for Python 3.9 was that \[64.7%\](https://github.com/di/pyreadiness/blob/50d28f9bcf62edf5f42e237082f1a3c93f8be3e1/docs/3.9/index.html#L69) of the most popular python packages had explicit support for 3.9 as stated on pypi.org.
> 
> |Date | Python 3.9 | Python 3.10 | Python 3.11 | Python 3.12|
> |------|-------------|--------------|---------------|--------------|
> |June 28th, 2023|\[78.6%\](https://github.com/di/pyreadiness/blob/a7f95961c5615d5eb336ad646fe3d1aae8cf8c55/docs/3.9/index.html#L95)|\[72.8%\](https://github.com/di/pyreadiness/blob/a7f95961c5615d5eb336ad646fe3d1aae8cf8c55/docs/3.10/index.html#L95)|\[51.7%\](https://github.com/di/pyreadiness/blob/a7f95961c5615d5eb336ad646fe3d1aae8cf8c55/docs/3.11/index.html#L95)||
> |August 24th, 2023|\[80.8%\](https://github.com/di/pyreadiness/blob/949c860148e24c6976ff8de76435e663e610d2da/docs/3.9/index.html#L95)|\[76.4%\](https://github.com/di/pyreadiness/blob/949c860148e24c6976ff8de76435e663e610d2da/docs/3.10/index.html#L95)|\[60.6%\](https://github.com/di/pyreadiness/blob/949c860148e24c6976ff8de76435e663e610d2da/docs/3.11/index.html#L95)||
> |October 28th, 2023|\[80.0%\](https://github.com/di/pyreadiness/blob/bad9df0eafc04ebf06bbd01ff97be2235a96e841/docs/3.9/index.html#L95)|\[76.1%\](https://github.com/di/pyreadiness/blob/bad9df0eafc04ebf06bbd01ff97be2235a96e841/docs/3.10/index.html#L95)|\[64.4%\](https://github.com/di/pyreadiness/blob/bad9df0eafc04ebf06bbd01ff97be2235a96e841/docs/3.11/index.html#L95)||
> |December 20th, 2023|\[80.8%\](https://github.com/di/pyreadiness/blob/b8ab80f82fcc088aa44b3ad9ed26151c70f301cb/docs/3.9/index.html#L95)|\[76.9%\](https://github.com/di/pyreadiness/blob/b8ab80f82fcc088aa44b3ad9ed26151c70f301cb/docs/3.10/index.html#L95)|\[67.5%\](https://github.com/di/pyreadiness/blob/b8ab80f82fcc088aa44b3ad9ed26151c70f301cb/docs/3.11/index.html#L95)||
> |March 4th, 2024|\[82.8%\](https://github.com/di/pyreadiness/blob/764e4520b314c28658f099299b3c7670280ffeb5/docs/3.9/index.html#L95)|\[78.9%\](https://github.com/di/pyreadiness/blob/764e4520b314c28658f099299b3c7670280ffeb5/docs/3.10/index.html#L95)|\[69.7%\](https://github.com/di/pyreadiness/blob/764e4520b314c28658f099299b3c7670280ffeb5/docs/3.11/index.html#L95)|\[48.6%\](https://github.com/di/pyreadiness/blob/764e4520b314c28658f099299b3c7670280ffeb5/docs/3.12/index.html#L95)|
> |May 17th, 2024|\[80.8%\](https://github.com/di/pyreadiness/blob/bfe7422e412f0305b6762dcefa4849a8bb05384e/docs/3.9/index.html#L95)|\[77.5%\](https://github.com/di/pyreadiness/blob/bfe7422e412f0305b6762dcefa4849a8bb05384e/docs/3.10/index.html#L95)|\[71.1%\](https://github.com/di/pyreadiness/blob/bfe7422e412f0305b6762dcefa4849a8bb05384e/docs/3.11/index.html#L95)|\[55.0%\](https://github.com/di/pyreadiness/blob/bfe7422e412f0305b6762dcefa4849a8bb05384e/docs/3.12/index.html#L95)|
> 
> \## Describe the solution you'd like
> 
> \- Update Slicer's Python from 3.9 to 3.10. 
> 
> Based on Slicer's previous update to Python 3.9 at 64.7% readiness and Python 3.10 at a higher readiness than that, this means Slicer can consider Python 3.10 ready to update to pending Python 3.10 support at:
> \- https://github.com/python-cmake-buildsystem/python-cmake-buildsystem
> \- https://github.com/python-cmake-buildsystem/python-cmake-buildsystem/pull/281
> 
> \## Describe alternatives you've considered
> 
> \- Update Slicer's Python from 3.9 to 3.11. This should be considered especially if the python-readiness for Python 3.11 (https://pyreadiness.org/3.11/) has increased when a developer begins to execute on this update.

Python 3.11 seems to be a good candidate for the next version that Slicer upgrades to. It will probably happen sometime this year though I don’t believe there is specific funding or plans for volunteered time to support this effort. @jcfr would probably know best.

@lukepolson since you are the primary developer of [`PyTomography`](https://github.com/qurit/PyTomography) can you describe what Python 3.11 specific features you use in your code that are not supported by Python 3.9? Would you be able to adapt your code to keep your Slicer extension development going if the Slicer python upgrade does not happen soon?

---

<div class="post-metadata">

**Author:** ![lukepolson](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lukepolson/32/76573_2.png) [@lukepolson](https://discourse.slicer.org/u/lukepolson)\
**Post date:** [July 19, 2024, 5:29pm UTC](https://discourse.slicer.org/t/python-3-11-upgrade/36235/3 "2024-07-19T17:29:58Z")

</div>

Hi @jamesobutler , sorry for the very late reply: I had thought I already replied here! We did end up changing a few things in PyTomography so that its compatible with python 3.9. Previously I was using features of Python 3.11 to perform array indexing using the unpacking (\*) operator, which isn’t available in earlier version of python. Changing the code required adding a few extra lines, but had no effect on any computational speed or anything. This may be something to be aware of when evaluating the importance of upgrading to python 3.11, as some developers of extensions may unknowingly use new features of the language.
