# Slicer's Python module picks up system numpy

**URL:** <https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063>\
**Category:** Development\
**Tags:** build\
**Created:** [September 15, 2017, 6:21pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063 "2017-09-15T18:21:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [September 15, 2017, 6:21pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/1 "2017-09-15T18:21:28Z")

</div>

I did a clean build of a recent version (9e9decc80e1bb922459799a260c558fc4ee90b06) yesterday. Build completed without errors. But when I try to run it, `DICOMScalarVolumePlugin.py` picks up system numpy which prevents some python modules from loading (many modules depend on DICOMScalarVolumePlugin in my own fork of Slicer). Stack trace is below.

This happens on Linux, but not on Windows. It also happens to a version of Slicer from August 3rd with a few cherry-picked commits on top. Did anyone encounter this? Any suggestions on how to fix it?

```
[461/461] Completed 'Slicer'
dzenan@corista:~/Slicer-rel$ Slicer-build/Slicer
Number of registered modules: 101 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/DICOMScalarVolumePlugin.py", line 1, in <module>
    import numpy
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/ __init__.py", line 180, in <module>
    from . import add_newdocs
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/ __init__.py", line 8, in <module>
    from .type_check import *
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/core/ __init__.py", line 14, in <module>
    from . import multiarray
ImportError: /home/dzenan/.local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: _PyUnicodeUCS4_IsWhitespace
loadSourceAsModule - Failed to load file "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/DICOMScalarVolumePlugin.py" as module "DICOMScalarVolumePlugin" ! 
Fail to instantiate module "DICOMScalarVolumePlugin" 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/Editor.py", line 4, in <module>
    import EditorLib
  File "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/EditorLib/ __init__.py", line 14, in <module>
    from PaintEffect import *
  File "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/EditorLib/PaintEffect.py", line 9, in <module>
    import numpy
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/ __init__.py", line 180, in <module>
    from . import add_newdocs
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/ __init__.py", line 8, in <module>
    from .type_check import *
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/core/ __init__.py", line 14, in <module>
    from . import multiarray
ImportError: /home/dzenan/.local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: _PyUnicodeUCS4_IsWhitespace
loadSourceAsModule - Failed to load file "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/Editor.py" as module "Editor" ! 
Fail to instantiate module "Editor" 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/MultiVolumeImporterPlugin.py", line 4, in <module>
    import vtk.util.numpy_support
  File "/home/dzenan/Slicer-rel/VTKv8-build/Wrapping/Python/vtk/util/numpy_support.py", line 30, in <module>
    import numpy
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/ __init__.py", line 180, in <module>
    from . import add_newdocs
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/ __init__.py", line 8, in <module>
    from .type_check import *
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/home/dzenan/.local/lib/python2.7/site-packages/numpy/core/ __init__.py", line 14, in <module>
    from . import multiarray
ImportError: /home/dzenan/.local/lib/python2.7/site-packages/numpy/core/multiarray.so: undefined symbol: _PyUnicodeUCS4_IsWhitespace
loadSourceAsModule - Failed to load file "/home/dzenan/Slicer-rel/Slicer-build/lib/Slicer-4.7/qt-scripted-modules/MultiVolumeImporterPlugin.py" as module "MultiVolumeImporterPlugin" ! 
Fail to instantiate module "MultiVolumeImporterPlugin" 
Number of instantiated modules: 98 
Number of loaded modules: 98 
Switch to module: "Welcome"
```

---

<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:** [September 15, 2017, 6:42pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/2 "2017-09-15T18:42:59Z")

</div>

I don’t know about best practices on Linux, but on Windows you are not supposed to pollute system or user environment settings with application-specific paths. If you modify paths (e.g., for your convenience you add some Python directories) then you are responsible for getting rid of those customizations when you launch an application.

---

<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:** [September 15, 2017, 7:05pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/3 "2017-09-15T19:05:44Z")

</div>

Hi Dzenan,

This is a known problem. We will implement a solution next week. In the  
mean time, talk to Forest.

Hth  
Jc

---

<div class="post-metadata">

**Author:** ![bpaniagua](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bpaniagua/32/20_2.png) [@bpaniagua](https://discourse.slicer.org/u/bpaniagua)\
**Post date:** [September 19, 2017, 4:59pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/4 "2017-09-19T16:59:03Z")

</div>

Has this been resolved? I am having the same problem in Ubuntu 16.04.

---

<div class="post-metadata">

**Author:** ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)\
**Post date:** [September 19, 2017, 9:54pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/5 "2017-09-19T21:54:00Z")

</div>

I don’t know if this is the same issue or not, but I had issues with local python - if I remember correctly, it went away after I removed the offending python from PATH and VIRTUAL\_ENV: [http://massmail.spl.harvard.edu/public-archives/slicer-devel/2013/033625.html](http://massmail.spl.harvard.edu/public-archives/slicer-devel/2013/033625.html)

---

<div class="post-metadata">

**Author:** ![forrest.li](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/forrest.li/32/13557_2.png) [@forrest.li](https://discourse.slicer.org/u/forrest.li)\
**Post date:** [September 20, 2017, 4:53pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/6 "2017-09-20T16:53:13Z")

</div>

Here’s a temporary workaround until Jc pushes the fix into slicer.

Open the file `SlicerLauncherSettings.ini` for editing. This should be in Slicer’s `bin/` dir. Under the heading “[EnvironmentVariables]”, add the following line:

```auto
PYTHONUSERBASE=<APPLAUNCHER_DIR>/lib/Python/lib/python2.7/site-packages

```

(Re)start slicer, and slicer should now be using the bundled numpy, so no more undefined symbols from numpy imports.

---

<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:** [September 20, 2017, 6:23pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/7 "2017-09-20T18:23:35Z")

</div>

Should this be set in the launcher settings by default?

---

<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:** [September 20, 2017, 7:00pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/8 "2017-09-20T19:00:31Z")

</div>

Yes. That is the plan but since this had other implications, more testing  
is required to confirm it doesn’t break anything else …

---

<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:** [January 25, 2018, 11:23pm UTC](https://discourse.slicer.org/t/slicers-python-module-picks-up-system-numpy/1063/9 "2018-01-25T23:23:35Z")

</div>

To follow up with this, back in december the issue was fixed in [r26688](http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&revision=26688) and the fix is included in Slicer 4.8.1.

Thanks @dzenanz for the report, and @forrest.li for his help understanding the problem.

Cc: @laurapascal
