. Advertisement .
..3..
. Advertisement .
..4..
The error: “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’” is a common error that can show up in many ways. In this blog, we will go through some of the ways you can fix this issue. Read on.
Why do you get the error: “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’”?
After installing SimpleITK, you can encounter the following error.
Exception has occurred: ModuleNotFoundError
No module named 'SimpleITK'
You have to encounter the “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’” because a library that SimpleITK relys on cannot be found. It’s possible that the dependant library’s version has changed and is no longer compatible with the Python environment.
There are many ways o fix this problem. You simply run this command to install. The second method is to install the module within the virtual environment using the command python -m pip install SimpleITK. Simply type python3 -m pip install SimpleITK to install the module. Next, simply refresh vscode by pressing Ctrl+Shift+P and selecting Reload window….
How to solve “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’”?
Approach 1: Install with the command below
To solve the “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’” error, you have to install SimpleITK by the following command:
python -m pip install SimpleITK
Before SimpleITK is installed, we strongly suggest you to creat a virtual environment for the package which can be installed. And note that different Python distributions and versions offer different tools for building and maintaining virtual environments. Using a virtual environment enables a user to easily resolve package compatibility problems.
A virtual environment is a tool used to create separate virtual Python environments for the dependencies needed by various projects, keeping them all in one location. It resolves the conflict that arises when “Project X depends on version 1.x but Project Y requires version 4.x” and maintains your global site-packages directory organized and tidy.
Approach 2: Ensure that the module is installed in the environment
Install the module within the virtual environment by using this command:
python3 -m pip install SimpleITK
Next, simply refresh vscode by pressing Ctrl+Shift+P and selecting Reload window.
Approach 3: Activate the environment
You also can fix this error by doing these steps:
- To begin with, access the Windows Terminal or cmd.
- Next activate the environment: conda activate <environment_name>
- Then, from the Terminal, launch Visual Studio Code: code
Approach 4: Install the Redistributable for Visual Studio package.
Excepting some solutions mentioned above, there is another way to fix the “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’” error. It is that you should set up the suitable Redistribution for the Visual Studio package. Although this way is very simple, it will give you amazing results.
Conclusion
We hope you enjoyed our article about the error. With this knowledge, we know that you can fix your error: “Exception has occurred: ModuleNotFoundError No module named ‘SimpleITK’” quickly by following these steps! If you still have any other questions about fixing this syntax error, please leave a comment below. Thank you for reading!
Leave a comment