# Import medpy fails

**URL:** <https://discourse.slicer.org/t/import-medpy-fails/3206>\
**Category:** Support\
**Tags:** python\
**Created:** [June 17, 2018, 8:34am UTC](https://discourse.slicer.org/t/import-medpy-fails/3206 "2018-06-17T08:34:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![virginia\_fgc](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/virginia_fgc/32/3309_2.png) [@virginia\_fgc](https://discourse.slicer.org/u/virginia_fgc)\
**Post date:** [June 17, 2018, 8:34am UTC](https://discourse.slicer.org/t/import-medpy-fails/3206/1 "2018-06-17T08:34:10Z")

</div>

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

---

<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:** [June 17, 2018, 8:03pm UTC](https://discourse.slicer.org/t/import-medpy-fails/3206/2 "2018-06-17T20:03:20Z")

</div>

Hi @virginia_fgc ,

Following [r27258](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=27258), 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/](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.

---

<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:** [June 18, 2018, 2:21pm UTC](https://discourse.slicer.org/t/import-medpy-fails/3206/3 "2018-06-18T14:21:04Z")

</div>

> [@jcfr](#):
>
> 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.).

---

<div class="post-metadata">

**Author:** ![virginia\_fgc](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/virginia_fgc/32/3309_2.png) [@virginia\_fgc](https://discourse.slicer.org/u/virginia_fgc)\
**Post date:** [June 20, 2018, 9:59pm UTC](https://discourse.slicer.org/t/import-medpy-fails/3206/4 "2018-06-20T21:59:15Z")

</div>

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](https://discourse.slicer.org/t/trying-to-update-a-slicer-volume-node-from-simpleitkimage/2032). 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

---

<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:** [June 21, 2018, 12:12am UTC](https://discourse.slicer.org/t/import-medpy-fails/3206/5 "2018-06-21T00:12:34Z")

</div>

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