# Slicer-Python Packages Use and Install

**URL:** <https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984>\
**Category:** Support\
**Created:** [August 31, 2017, 9:27pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984 "2017-08-31T21:27:14Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)\
**Post date:** [March 8, 2019, 4:24am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/43 "2019-03-08T04:24:50Z")

</div>

> [@lassoan](#):
>
> Start Slicer as administrator: in the start menu, instead of left-click on the Slicer icon, use right-click, then select `More...` and `Run as Administrator` .

Hi, I’m having the same problem when I try to install packages to my computer. I tried the pip way as you described but it did not work for me. No matter what package I try to install, it always report to following errors:  
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ‘/private/var/folders/4m/3zz84kjj0rb8r7twkxksmplw0000gn/T/pip-req-tracker-dVJBGY/39e3ab1dfb11346e7d530d2e1ee1ef3dc8bbf9578e5f497994026cda’  
and some times like this: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: ‘/Volumes/Slicer-4.10.0-macosx-amd64/Slicer.app/Contents/lib/Python/lib/python2.7/site-packages/python\_dateutil-2.8.0.dist-info’  
I was wondering if this is because I didn’t run slicer as an administrator. I’m using mac and when I right click on the icon, I didn’t see more and run as administrator. Does anyone know to run slicer on mac as an administrator? And does anyone know how to fix this error?  
Please help.

Thanks,  
Andrea

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [March 8, 2019, 12:05pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/44 "2019-03-08T12:05:25Z")

</div>

Hi - it looks like you didn’t drag the application to a writable location.

[https://www.slicer.org/wiki/Documentation/4.10/SlicerApplication/Installation#Mac](https://www.slicer.org/wiki/Documentation/4.10/SlicerApplication/Installation#Mac)

---

<div class="post-metadata">

**Author:** ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)\
**Post date:** [March 9, 2019, 2:20am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/45 "2019-03-09T02:20:42Z")

</div>

Hi, Thank you for the advice! I checked and I think Slicer is at a writable location right now. And I also tried to open it as an administrator by command _Applications andrealiang$ sudo open Slicer.app_ at the terminal. But I still get the following error:  
_Requirement already satisfied: pandas in ./Slicer.app/Contents/lib/Python/lib/python2.7/site-packages (0.24.1)_

_Requirement already satisfied: python-dateutil\>=2.5.0 in ./Slicer.app/Contents/lib/Python/lib/python2.7/site-packages (from pandas) (2.8.0)_

_Requirement already satisfied: numpy\>=1.12.0 in ./Slicer.app/Contents/lib/Python/lib/python2.7/site-packages/numpy-1.13.1-py2.7-macosx-10.9-x86\_64.egg (from pandas) (1.13.1)_

_Requirement already satisfied: pytz\>=2011k in ./Slicer.app/Contents/lib/Python/lib/python2.7/site-packages (from pandas) (2018.9)_

_Requirement already satisfied: six\>=1.5 in ./Slicer.app/Contents/lib/Python/lib/python2.7/site-packages (from python-dateutil\>=2.5.0-\>pandas) (1.11.0)_

_Collecting importlib_

_Using cached [https://files.pythonhosted.org/packages/31/77/3781f65cafe55480b56914def99022a5d2965a4bb269655c89ef2f1de3cd/importlib-1.0.4.zip](https://files.pythonhosted.org/packages/31/77/3781f65cafe55480b56914def99022a5d2965a4bb269655c89ef2f1de3cd/importlib-1.0.4.zip)_

_Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ‘/private/var/folders/4m/3zz84kjj0rb8r7twkxksmplw0000gn/T/pip-req-tracker-rEfQlE/20483040384e67f98bad799531b988be6a42bb897823a965fb554d64’_

It looks like it has already installed the package pandas, but is having trouble with the second package. Does anyone know how to fix this bug?

Thanks!  
Andrea

---

<div class="post-metadata">

**Author:** ![ZiyunLiang](https://avatars.discourse-cdn.com/v4/letter/z/5daacb/32.png) [@ZiyunLiang](https://discourse.slicer.org/u/ZiyunLiang)\
**Post date:** [March 11, 2019, 2:42am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/46 "2019-03-11T02:42:39Z")

</div>

Hi everyone, after days of trying, my problem is solved in two ways. And I’d like to share my solutions with you.

1. As for me, I’m using mac, and to successfully install the packages, mac users need to put the software in the directory Users/_yourname_/Applications rather than /Applications. Or if your software is in the directory /Applications, you can open it by option+open
2. you can use multithreading, which is _to run Python script using a non-Slicer Python environment_ as described [here](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_run_Python_script_using_a_non-Slicer_Python_environment).

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [March 13, 2019, 2:21pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/47 "2019-03-13T14:21:42Z")

</div>

> [@ZiyunLiang](#):
>
> you can use multithreading, which is _to run Python script using a non-Slicer Python environment_ as described [here](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_run_Python_script_using_a_non-Slicer_Python_environment).

I don’t get your point, no matter what I am not able to run multithreading, all packages run in a single processor even if they split threads. I have tried with multiprocessing, cython, numba, ipyparallel, joblib, handythreads. Everything has same behaviour, yes they can be installed but multithreading is just not working. Using an external python for this is not efficient since you have to pass big arrays (files). Can you elaborate more this point please?

---

<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:** [March 13, 2019, 2:28pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/48 "2019-03-13T14:28:41Z")

</div>

> [@Alex\_Vergara](#):
>
> Using an external python for this is not efficient since you have to pass big arrays (files)

Have you actually measured the time to pass large arrays through files? My experience is that if you don’t use compression then it works extremely fast. I guess that pickling of numpy arrays is quite well optimized, too. If you find that data transfer is the performance bottleneck then you can go lower level and use shared memory transfer.

---

<div class="post-metadata">

**Author:** ![roberta](https://avatars.discourse-cdn.com/v4/letter/r/f19dbf/32.png) [@roberta](https://discourse.slicer.org/u/roberta)\
**Post date:** [April 2, 2019, 11:00am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/50 "2019-04-02T11:00:50Z")

</div>

Hi!! i have 4.11 slicer version. I’d like to know if there is a way to display the spect / ct on slicer

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [April 4, 2019, 3:02pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/53 "2019-04-04T15:02:12Z")

</div>

@roberta Please create a new thread with your question and please gives us more information on what you want to do so we can help you.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [July 22, 2019, 9:53am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/54 "2019-07-22T09:53:08Z")

</div>

Hello Developers,

I am trying to install python packages from Python interactor but it gives error.

I am using Slicer 4.10 in Linux Centos 7 OS

I am trying like this:

```
import pip 
pip.main(['install', 'scipy'])

```

but it gives this error:

AttributeError: ‘module’ object has no attribute ‘main’

I have also tried with build tree but it gives the same error. Can you please help me with installing Python packages.

thank you so much for all your support.

---

<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:** [July 22, 2019, 11:40am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/55 "2019-07-22T11:40:42Z")

</div>

For Slicer 4.10 I would probably suggest opening a terminal window to the location of PythonSlicer and doing `PythonSlicer.exe -m pip install scipy`. The error you are getting is because the “pip” package was updated and “main” was moved out. You could try some work around as was suggested earlier in this discussion such as

```auto
from pip._internal import main as pipmain
pipmain(['install','scipy'])

```

If using Slicer 4.11, Slicer is now using Python3. You could also use a helper function within Slicer’s python interactor. Try `slicer.util.pip_install('scipy')`.  
Reference: [Use full power of Python in Slicer](https://discourse.slicer.org/t/use-full-power-of-python-in-slicer/7162)

Note: If you install scipy in Slicer 4.10, which is using python2, you will **not** be using the latest version of scipy (1.3.0). Scipy 1.3.0 is only available for Python3.

---

<div class="post-metadata">

**Author:** ![fpsiddiqui91](https://avatars.discourse-cdn.com/v4/letter/f/53a042/32.png) [@fpsiddiqui91](https://discourse.slicer.org/u/fpsiddiqui91)\
**Post date:** [July 22, 2019, 1:08pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/56 "2019-07-22T13:08:12Z")

</div>

Thank you so much for your response. it worked. I am also going to update Slicer to 4.11.

Thank you again

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 23, 2019, 8:35am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/57 "2019-07-23T08:35:34Z")

</div>

> [@Saima](#):
>
> pipmain([‘install’,‘scipy’])

pipmain([‘install’,‘pynrrd’])

Collecting pynrrd

Using cached [https://files.pythonhosted.org/packages/75/db/d0b421a9cbf84ce2af6f95e433f472b6a49e27e9355c027c8680ca9163af/pynrrd-0.4.0-py2.py3-none-any.whl](https://files.pythonhosted.org/packages/75/db/d0b421a9cbf84ce2af6f95e433f472b6a49e27e9355c027c8680ca9163af/pynrrd-0.4.0-py2.py3-none-any.whl)

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ‘C:\Users\22374464\AppData\Local\Temp\pip-req-tracker-de0bnyq2\038c22fe9d64f3b52795137322e50c0d971005e9da8841928046b4a7’

Any idea of how to install pynrrd

---

<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:** [July 23, 2019, 9:53am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/58 "2019-07-23T09:53:10Z")

</div>

Since you had issues using pipmain and I’m assuming you are using Slicer 4.10, then you should try `PythonSlicer.exe -m pip install pynrrd` to install this pure python package. Don’t use pipmain if you’re using Slicer 4.11 nightly.

If you’re using Slicer 4.11 nightly, you can easily use `slicer.util.pip_install('pynrrd')`as stayed above.

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 23, 2019, 9:58am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/59 "2019-07-23T09:58:42Z")

</div>

> [@jamesobutler](#):
>
> slicer.util.pip\_install(‘pynrrd’)

i am using slicer 4.11.0 nightly

I followed and got  
slicer.util.pip\_install(‘pynrrd’)  
Collecting pynrrd  
Using cached [https://files.pythonhosted.org/packages/75/db/d0b421a9cbf84ce2af6f95e433f472b6a49e27e9355c027c8680ca9163af/pynrrd-0.4.0-py2.py3-none-any.whl](https://files.pythonhosted.org/packages/75/db/d0b421a9cbf84ce2af6f95e433f472b6a49e27e9355c027c8680ca9163af/pynrrd-0.4.0-py2.py3-none-any.whl)  
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ‘C:\Users\22374464\AppData\Local\Temp\pip-req-tracker-de0bnyq2\038c22fe9d64f3b52795137322e50c0d971005e9da8841928046b4a7’

Traceback (most recent call last):  
File “”, line 1, in   
File “C:\Users\22374464\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-06\bin\Python\slicer\util.py”, line 2002, in pip\_install  
logProcessOutput(proc)  
File “C:\Users\22374464\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-06\bin\Python\slicer\util.py”, line 1955, in logProcessOutput  
raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)  
subprocess.CalledProcessError: Command ‘[‘C:/Users/22374464/AppData/Local/NA-MIC/Slicer 4.11.0-2019-07-06/bin/…/bin\PythonSlicer.EXE’, ‘-m’, ‘pip’, ‘install’, ‘pynrrd’]’ returned non-zero exit status 1.

> > >

---

<div class="post-metadata">

**Author:** ![Alex\_Vergara](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/alex_vergara/32/15205_2.png) [@Alex\_Vergara](https://discourse.slicer.org/u/Alex_Vergara)\
**Post date:** [July 23, 2019, 10:00am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/60 "2019-07-23T10:00:47Z")

</div>

I see you are using windows, therefore you have installed Slicer into Programs files folder without writing permissions for slicer. You shall uninstall Slicer and reinstall in a writable folder like Documents, etc. This will solve your problems.

---

<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:** [July 23, 2019, 1:30pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/61 "2019-07-23T13:30:40Z")

</div>

It seems that it is a recent Slicer Preview version, which installs itself to a writeable location by default, so write access should not be an issue.

`pynnrd` does not seem to be available on PyPI:

```nohighlight
>>> pip_install('pynnrd')
Loading Slicer RC file [C:/Users/andra/.slicerrc.py]
Collecting pynnrd
  Could not find a version that satisfies the requirement pynnrd (from versions: )
No matching distribution found for pynnrd
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\Users\andra\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-15\bin\Python\slicer\util.py", line 2002, in pip_install
    logProcessOutput(proc)
  File "C:\Users\andra\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-15\bin\Python\slicer\util.py", line 1955, in logProcessOutput
    raise CalledProcessError(retcode, proc.args, output=proc.stdout, stderr=proc.stderr)
subprocess.CalledProcessError: Command '['C:/Users/andra/AppData/Local/NA-MIC/Slicer 4.11.0-2019-07-15/bin/../bin\\PythonSlicer.EXE', '-m', 'pip', 'install', 'pynnrd']' returned non-zero exit status 1.

```

On your computer, there seem to be some cached pynrrd package, which is probably not compatible.

You should not need to import basic functionalities such as nrrd file reading from python.

You can read a nrrd file using `vol=slicer.util.loadVolume('something.nrrd')`, if you want to access it as a numpy array, call `a=slicer.util.arrayFromVolume(vol)`. This approach has the advantage that you can directly manipulate the voxels that Slicer displays.

---

<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:** [July 23, 2019, 2:58pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/62 "2019-07-23T14:58:28Z")

</div>

@lassoan The output error you posted happened because you tried to install `pynnrd` instead `pynrrd`. Just a simple typo.

I was able to successfully install this `pynrrd` package using `slicer.util.pip_install('pynrrd')`. I do think the previous errors have been due to some messed up cache of the download. Deleting that cache and then retrying should work.

---

<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:** [July 23, 2019, 4:12pm UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/63 "2019-07-23T16:12:27Z")

</div>

> [@jamesobutler](#):
>
> The output error you posted happened because you tried to install `pynnrd` instead `pynrrd` . Just a simple typo.

Good catch, thank you!

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [July 29, 2019, 6:40am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/64 "2019-07-29T06:40:53Z")

</div>

thankyou so much yes it was a typo

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/a/9a2b6f84929cebe9793f8fa5a6d0b21d389052e3.png)

---

<div class="post-metadata">

**Author:** ![Saima](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Saima](https://discourse.slicer.org/u/Saima)\
**Post date:** [August 27, 2019, 1:40am UTC](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984/65 "2019-08-27T01:40:34Z")

</div>

Hi Andras,  
gmsh-api is I need it within slicer. its succesfully installed but there is problem in using it within slicer. could you please help how to resolve the issue:

> > > pip\_install(“gmsh-api”)

Requirement already satisfied: gmsh-api in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages (0.1.5)

Requirement already satisfied: pandas in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages (from gmsh-api) (0.25.1)

Requirement already satisfied: numpy in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages\numpy-1.16.2-py3.6-win-amd64.egg (from gmsh-api) (1.16.2)

Requirement already satisfied: python-dateutil\>=2.6.1 in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages (from pandas-\>gmsh-api) (2.8.0)

Requirement already satisfied: pytz\>=2017.2 in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages (from pandas-\>gmsh-api) (2019.2)

Requirement already satisfied: six\>=1.5 in c:\users\22374464\appdata\local\na-mic\slicer 4.11.0-2019-07-06\lib\python\lib\site-packages (from python-dateutil\>=2.6.1-\>pandas-\>gmsh-api) (1.12.0)

but when I import the gmsh and try to run a script it gives me error. I am posting error below: The api works well on anaconda. I have used it before.  
File “C:/Users/22374464/AppData/Local/NA-MIC/Slicer 4.11.0-2019-07-06/Mesher/MeshCreator/MeshCreator.py”, line 165, in run  
import gmsh\_api.gmsh as gmsh  
File “C:\Users\22374464\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-06\lib\Python\Lib\site-packages\gmsh\_api\gmsh.py”, line 39, in   
lib = CDLL(libpath)  
File “C:\Users\22374464\AppData\Local\NA-MIC\Slicer 4.11.0-2019-07-06\lib\Python\Lib\ctypes\__init_\_.py”, line 348, in **init**  
self.\_handle = \_dlopen(self.\_name, mode)  
TypeError: LoadLibrary() argument 1 must be str, not None

[Previous page](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984.md?page=2)

[Next page](https://discourse.slicer.org/t/slicer-python-packages-use-and-install/984.md?page=4)
