Import medpy fails

Operating system: Windows
Slicer version: 4.8.0

Hello everyone,

I am using the Python Console in Slicer to work with a MR image, and I am facing problems when importing some modules. I wanted to use cv2 and medpy. I managed to find a workaround for which I did not need cv2, but I need to use medpy and I am getting stuck with its import.

I ran the following commands:

import pip
pip.main([‘install’, ‘medpy’])

The errors in the output were:
Failed building wheel for medpy
Failed cleaning build dir for medpy
Traceback (most recent call last):
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\basecommand.py”, line 215, in main
status = self.run(options, args)
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\commands\install.py”, line 342, in run
prefix=options.prefix_path,
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\req\req_set.py”, line 784, in install
**kwargs
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\req\req_install.py”, line 851, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\req\req_install.py”, line 1064, in move_wheel_files
isolated=self.isolated,
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\wheel.py”, line 345, in move_wheel_files
clobber(source, lib_dir, True)
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\wheel.py”, line 316, in clobber
ensure_dir(destdir)
File “C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\pip\utils_init_.py”, line 83, in ensure_dir
os.makedirs(path)
File “C:/Program Files/Slicer 4.8.0/lib/Python/Lib\os.py”, line 157, in makedirs
mkdir(name, mode)
WindowsError: [Error 5] Access denied: ‘C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\scipy’
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the ‘python -m pip install --upgrade pip’ command.

Now, the upgrade command does not work. I tried to use CMD directly, but the system keeps triggering Syntax Errors and ‘File not found’ errors. Strangely, the default 2.7 Python version of mi computer does not have pip installed; thus, I can’t use pip to install any module. “Import pip” does work with Slicer though. However, it doesn’t seem to be working either due to the errors I mention above.

Questions:

  1. Do I have to consider the Python 2.7 version in Slicer and the Python 2.7 version in my computer as different things? Can’t I attempt the installation of a module for the Python console in slicer in CMD, with permits?
  2. How do I run command “python -m pip install --upgrade pip”? In the Slicer console it clearly does not work. In Windows console, neither (because it tells me “pip” does not exist and so on).

Thank you for any clarification.

Virginia

Hi @virginia_fgc ,

Following r27258, the version of pip bundled in Slicer has been updated to 10.0.1. This means that the nightly build of tomorrow will include an updated pip version. See https://download.slicer.org/

WindowsError: [Error 5] Access denied: ‘C:\Program Files\Slicer 4.8.0\lib\Python\Lib\site-packages\

Since Slicer is installed in C:\Program Files, you may have to run the command from a windows terminal started with administrator rights.

I need to use medpy

If you describe the processing you would like to achieve, we may be able to describe an approach using filters readily available in Slicer.

I’ve been thinking about the same, too. This medpy package seems pretty basic (random wrapping of selected features from other toolkits) and there are several red flags (essentially a single contributor, overly generic package name - the developer thinks that a single package can cover this vast area; ignoring image axis orientation - an error that an experienced medical image computing software developer would never do; etc.). Overall, I would not recommend to rely on medpy package and instead use directly ITK (SimpleITK), VTK, numpy, etc. These toolkits are already bundled with Slicer and Slicer offers some additional features (for DICOM import, segmentation, quantification, etc.).

1 Like

Dear Jean Cristophe, and Andras,

Thank you both for the updates. I am starting using Python and Slicer together, I am still struggling with issues like how after processing an image as an array, I can refresh the screen. I get from Andras’ reply that I can do it with ITK/VTK easily, just have to figure out how exactly. Problem is that I need to address many different issues and I am relying on discussions about similar problems where non-default modules are used.

I will try to go on with numpy and ITK/VTK only, see if I can. I basically need to process a series of arrays that I need to read from a txt file and external images, and then change the color of some elements in the input volume based on the result of that image + array processing. For now, I’ve managed to go on without other modules. I’ve just found a discussion that might help me with the particular issue I’m having now: Trying to update a slicer volume node from SimpleITKImage. Nonetheless, I’ll still implement the last nightly built version just in case I need to use pip in the future.

Thank you very much for the quick replies.

VIrginia

OK. We will be happy to help, just post on the forum as new topics any specific questions that you cannot find answer for.