SimpleITK and Python 3.11

Hello, the SimpleITK 1.2.4 library does not connect to the project and the error keeps appearing: ModuleNotFoundError: no module named ‘simpleitk._simpleitk’. Python version is 3.11. Spyder version is 5.4. When using the command prompt, a completely similar problem occurs. Link to the project - GitHub - biomedia-mira/blast-ct: Brain Lesion Analysis and Segmentation Tool for Computed Tomography

Hello @Wallesss,

Python 3.11 was released in 2022, SimpleITK 1.2.4 was released in 2019 so there are no SimpleITK wheels for that combination. The latest version of Python supported by the SimpleITK 1.2.4 release is Python 3.8. Bottom line, SimpleITK is not installed in the development environment.

Things to try in order of complexity:

  1. Use Python 3.8 instead of 3.11 and everything will work out of the box.
  2. Use Python 3.11 and hope for the best. Upgrade to SimpleITK 2.2.1 or above (2.2.1 was the first release with wheels for Python 3.11). If lucky, the original code does not need to be modified. If unlucky, evaluate the amount of code change necessary. Hope the changes are minimal.
  3. Use Python 3.11, no changes to your code, and build SimpleITK 1.2.4 locally. Create the wheel using Python 3.11.
2 Likes

I tried to create a virtual environment in spyder, but the spyder-kernels library does not work with python 3.8.

Hello @Wallesss,

Not sure what you mean by “spyder-kernels”. You can set up a virtual environment using venv for plain Python or conda for the anaconda distribution. Install spyder into the virtual environment and then work there.

  1. I created a virtual environment using the command ‘conda create --name envspy’. 2) Activated the environment - ‘conda activate envspy’. 3) Installed the necessary libraries - ‘conda install spyder-kernels python=3.8.10’ and some others. 4) I received an error in the screenshot - d9c37b0408219277bc361d771f24056a.png hosted at IMGTR - IMGTR

FYI, I was able to create a python virtual environment using anaconda, install spyder via conda, and install SimpleITK 1.2.4 using pip.

Then I launched spyder, and in spyder my SimpleITK test code worked.

Looking at your conda create, maybe try setting python=3.8.

1 Like

It turns out that the virtual environment does not work because ‘python=3.8.10’ was specified rather than ‘python=3.8’. I understand correctly? Spyder IDE was installed using an exe file.

“spyder-kernels” is mentioned in this video - https://youtu.be/i7Njb3xO4Fw?t=96

No, I think when you initially create the environment, you need to specify the python version. Here’s how I create my environment:

conda create -n spyder python=3.8
conda activate spyder
conda install spyder
pip install simpleitk==1.2.4

spyder # launch spyder

What you’ve done is to create a python environment with the default python version (probably 3.11), and then tried to install the py3.8 version of Spyder-kernels into it, which won’t work.

What is “conda install spyder”? Will a second Spyder IDE be installed on my computer?

Yes, that is the way I installed spyder. I did it within the conda environment to ensure that I was getting the python version that I wanted.

Will I be able to connect the environment created using your method to the Spyder IDE, as shown in this video? Link to video - https://youtu.be/i7Njb3xO4Fw?t=96

It should be able to. When I type in spyder, it launches the IDE.

But I already downloaded and installed Spyder IDE 5.4 from offline installers. Do I need to remove the currently installed Spyder IDE? Thanks for the dialogue.

You can remove that other Spyder if you want to. It probably is a good idea to keep things clean.

Can I install additional libraries using pip, such as torch, numpy, tensorflow, tensorboard?

Yes, you can pip install any packages and they will get installed into the currently active anaconda environment.

That is, I can easily connect torch in code written in Spyder IDE, which will be installed with the command “conda install spyder”?

Yes, you will have to restart the python kernel, I think, then torch will be available. Or you can restart the whole Spyder IDE.