Slicer's Python module picks up system numpy

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"

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.

Hi Dzenan,

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

Hth
Jc

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

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

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:

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.

1 Like

Should this be set in the launcher settings by default?

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

To follow up with this, back in december the issue was fixed in r26688 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