View Issue Details

IDProjectCategoryView StatusLast Update
0001180Slicer4Core: Base Codepublic2017-06-07 23:27
Reporterlassoan Assigned Tojcfr  
PrioritylowSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version 
Target VersionSlicer 4.3.0Fixed in VersionSlicer 4.3.0 
Summary0001180: Slicer might load the wrong Python and other dlls
Description

The launcher adds the Slicer directories to the PATH env
variable, but first the dlls are attempted to be loaded from the system
directories (http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx).
Therefore if any application installs any python, QT, ITK, VTK, etc. dll
into the system directories then Slicer may crash (or work incorrectly).

TagsNo tags attached.

Activities

lassoan

lassoan

2011-05-30 13:28

developer   ~0002464

From: Steve Pieper [mailto:pieper@ibility.net]
Sent: Tuesday, May 24, 2011 5:20 PM
To: Andras Lasso
Cc: slicer-devel@bwh.harvard.edu
Subject: Re: [slicer-devel] Slicer4 launcher problem

Hi Andras -

Very good catch - this will impact developers, but not users, since the python dll is put in the bin directory by the installer as part of cpack.

In general though it seems the windows side-by-side is the 'correct' solution for windows builds. Although it is a pain, it should probably be done automatically as part of the build process.

It looks like there's some support for this in cmake:

http://www.kitware.com/blog/home/post/4

Alternatively we could copy the python dlls (and others) into the Slicer-build/bin/<type> directory as part of the build process rather than as part of the packaging process.

-Steve

On Tue, May 24, 2011 at 11:00 AM, Andras Lasso <lasso@cs.queensu.ca> wrote:
Hi all,

I tried to build and test Slicer4 on Windows 7. The build was OK, but it
didn't start (error: [bin/Release/SlicerQT-real.exe] exit abnormally -
Report the problem.)

I've found that copying python26.dll into the ...\Slicer-build\bin\Release\
directory solves the problem. There is a c:\Windows\System32\python26.dll on
my system (installed by some application). If I remove the python26.dll from
system32 then Slicer starts correctly (there is no need to copy the new
python26.dll into the release directory). The python26.dll version in
system32 is 2.6.2, the Slicer-built python26.dll is 2.6.6.

The problem is that the launcher adds the Slicer directories to the PATH env
variable, but first the dlls are attempted to be loaded from the system
directories (http://msdn.microsoft.com/en-us/library/ms682586(VS.85).aspx).
Therefore if any application installs any python, QT, ITK, VTK, etc. dll
into the system directories then Slicer may crash.

The problem was the same with Slicer3 and tcl, but probably tcl changed less
often or dll versions with the same filename (tcl84.dll) were more
compatible with each other than python. A safe solution could be to install
all the required dlls into the bin directory (then there would be no need
for a launcher at all) or use side-by-side assemblies to make sure that the
correct dll versions are loaded.

Andras

gregsharp

gregsharp

2012-01-19 07:01

developer   ~0003506

I also ran into this problem, and confirm that it was solved by deleting python26.dll from c:\windows\system32 directory.

After deleting python26.dll, I could no longer run python.exe. Perhaps the dll is installed to that location by an official windows python binary.

jcfr

jcfr

2012-04-25 18:37

administrator   ~0004082

Last edited: 2012-04-25 18:38

Andras> Would it be possible to confirm using dependency walker ?

Greg> Could you confirm that python.exe and python26.dll built by Slicer are located in the same folder ?

lassoan

lassoan

2012-04-26 06:32

developer   ~0004085

I confirm that dependency walker shows python26.dll is loaded from c:\windows\system32 if python26.dll is installed in the windows system directories and python26.dll is not available in the executable's directory.

This is the case when attempting to run Slicer from the build tree.

This would happen also if you started any exe that is not located in Slicer 4.1.0\bin uses python (or loads a python-using dll). Fortunately, with the current CLIs this cannot happen, as none of them use python. The problem may happen when somebody tries to launch a python scripted module from command line using python.exe.


The crash when starting Slicer from the build tree could be prevented by adding a line to one of the CMakeLists.txt files to copy Python26.dll into the SlicerQt-real.exe directory.

lassoan

lassoan

2012-04-26 06:34

developer   ~0004086

It was some time ago when I last checked this, but normally the Python installer copies:

  • Python.exe (and many other files) into c:\Python26\python.exe
  • Python26.dll into the windows system directories (it appears in c:\Windows\SysWOW64\python26.dll in the file system, depends reports c:\windows\system32)

2012-06-25 15:45

 

jcfr

jcfr

2012-06-25 15:47

administrator   ~0004937

It seems the problem is resolved. See enclosed screenshot

jcfr

jcfr

2012-07-27 15:36

administrator   ~0005303

Dear issue reporter,

Good news :) Slicer developers SOLVED the problem you reported - YOU now need to VERIFY and CLOSE this issue.

lassoan

lassoan

2012-07-27 17:24

developer   ~0005430

The problem still exists. How to reproduce:

  • Install the latest available Python 2.6.x release (http://www.python.org/download/releases/2.6.6/) with default options
    => it copies Python26.dll into the system directories (e.g., c:\Windows\System32\python26.dll)
  • Start Slicer in release mode
    => After the splash screen disappears nothing appears, Slicer nevers starts up.

Notes:

  1. If Slicer and Python release bitness (32-bit or 64-bit) is different then the problem does not occur. Installation of the 32-bit Python release breaks only the 32-bit Slicer release. Installation of the 64-bit Python release breaks only the 64-bit Slicer release.

  2. Installed Slicer Releases are not impacted, because the Slicer application exe and Python26.dll are in the same directory.

  3. The problem occurs with both release and debug builds.

jcfr

jcfr

2012-09-04 12:19

administrator   ~0005959

This issue affects only developer and based on today hangout discussion, it has been re-targeted for 4.3

pieper

pieper

2013-04-25 12:08

administrator   ~0008490

Same issue has cropped up again:

http://massmail.spl.harvard.edu/public-archives/slicer-devel/2013/012307.html

jcfr

jcfr

2013-04-25 12:21

administrator   ~0008491

Last edited: 2013-04-25 12:25

Updated documentation link to "Search Path Used by Windows to Locate a DLL"
See http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.90).aspx

1) Immediate solution: As part of the Slicer build process, we could copy the python library along side the qSlicerApp-real.exe executable.

2) Alternative/complementary solution: If there is a system python (matching the requirement) available on the windows machine, it could/should probably be used.

While solution (1) will fix that specific issue, should we detect if there are itk/qt/vtk/... already available on the system and warn the developer ? If not, unexpected problem will arise. Should we also copy DLL of VTK, ITK, ... along side the executable ?

We could also ask VTK/ITK/.. to build their library along side the Slicer executable. That would avoid issue but would prevent the developer from deleting Slicer-build inner directory without having to rebuild everything.

ungi

ungi

2013-04-25 12:51

developer   ~0008492

Note that this issue somehow became more problematic now (probably because of external reasons). While Andras and Greg could uninstall python 2.6 from their systems to get Slicer start up, I cannot start Slicer now, even after uninstalling Python 2.7. And this is confirmed on other computers too.

So an immediate solution (as in the previous comment) would be much appreciated.

jcfr

jcfr

2013-04-25 13:12

administrator   ~0008494

@ungi: Could you investigate why Slicer fails to start even after removing the problematic from system folder. What is the output of dependency walker in that case.

Note that solution (1) will be implemented, Just want to have a better understanding of what is going on.

inorton

inorton

2013-04-25 13:20

developer   ~0008497

Have you tried using SetDllDirectory [1] to override the search path, so that the slicer directories are used first? If this is called by the launcher, then any subsequent loadlibrary calls within the process should respect the modified path.

[1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms686203(v=vs.85).aspx

jcfr

jcfr

2013-04-25 13:47

administrator   ~0008498

Seems that "SetDllDirectory" is useful when relying on "LoadLibrary" in case of explicit linking.

Some interesting readings about the topic:
http://www.binaryplanting.com/guidelinesDevelopers.htm
http://www.pretentiousname.com/setdlldirectory_inheritance/index.html
http://msdn.microsoft.com/en-us/library/784bt7z7%28v=VS.100%29.aspx

As explained here, explicit linking would be complex process for an application like Slicer: http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/9a70abb2-ee8e-4c91-8d88-cdb213c5832e/

As of today, copying the python library along side the executable seems to be a good compromise.

If we encounter issue with VTK, ITK, .. libraries, we could also copy them along side the executable.

ungi

ungi

2013-04-25 13:48

developer   ~0008499

Dependency Walker says:
"e:\Slicer4\Debug\Slicer-build\PYTHON27.DLL was not found."
However, the file is there. I don't know why is it not found.

When staring Slicer from Visual Studio (in Debug 64-bit mode) it says in the output window:
'SlicerApp-real.exe': Loaded 'C:\Windows\System32\python27.dll'
However, the file is NOT there! And there aren't any other python27.dll files accessible on my computer (only the ones that come with Slicer).

jcfr

jcfr

2013-04-25 13:59

administrator   ~0008500

Last edited: 2013-04-25 14:54

Humm ... after doing a regular build, there are no file "e:\Slicer4\Debug\Slicer-build\PYTHON27.DLL" but "e:\Slicer4\Debug\Slicer-build\python-install\bin\python27.dll" should exist.

Do you confirm you started both dependency walker and visual studio using the slicer launcher ?

ungi

ungi

2013-04-25 14:42

developer   ~0008502

Sorry, you are right. None of the files exist.
Yes, I started both by Slicer.exe --launch ...

ungi

ungi

2013-04-25 14:47

developer   ~0008503

I deleted every entry from my Windows Registry that included "System32\python27". There were a few. But the problem is still the same when I try to run Slicer from Visual Studio.

jcfr

jcfr

2013-04-25 14:55

administrator   ~0008504

Do you mean that the following file does not exist:
"e:\Slicer4\Debug\Slicer-build\python-install\bin\python27.dll"

If it does NOT exist, it means there is any issue building python that should be addressed first.

ungi

ungi

2013-04-25 15:13

developer   ~0008506

Last edited: 2013-04-25 15:14

No.

e:\Slicer4\Debug\Slicer-build\PYTHON27.DLL
--- does not exist.

C:\Windows\System32\python27.dll
--- does not exist.

e:\Slicer4\Debug\Slicer-build\python-install\bin\python27.dll
--- exists. But sadly, Slicer is not looking for it when starting from Visual Studio...

jcfr

jcfr

2013-04-26 13:19

administrator   ~0008521

Fixed in r21943
See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21943

jcfr

jcfr

2013-04-26 14:18

administrator   ~0008523

Follow up commit r21948
See http://viewvc.slicer.org/viewvc.cgi/Slicer4?view=revision&amp;revision=21948

It fixes error reported on the dashboard:

// ---------------
19>91>Copy 'python27.dll' along side 'SlicerApp-real' executable. See Slicer issue 0001180
19>91>Error copying file (if different) from "/python27.dll" to "/.../Slicer-1-build/Slicer-build/bin/Release".
19>91>Project : error PRJ0019: A tool returned an error code from "Copy 'python27.dll' along side 'SlicerApp-real' executable. See Slicer issue 0001180"
// ---------------

See http://slicer.cdash.org/viewBuildError.php?buildid=91379

jcfr

jcfr

2014-03-06 04:53

administrator   ~0010787

Closing resolved issues that have not been updated in more than 3 months

jcfr

jcfr

2017-06-07 23:27

administrator   ~0014646

Fix committed to 2145-support-for-installing-extension-from-file branch.

Related Changesets

Slicer: 2145-support-for-installing-extension-from-file 689851c3

2013-04-26 17:19:08

jcfr

Details Diff
BUG: Fix startup crash due to improper dynamic linking of python dll

This problem affect the a windows build tree of Slicer.

On windows, as explained in [1], system path are searched before path
appended to PATH variable.

[1] Title: Search Path Used by Windows to Locate a DLL
Link: http://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.90).aspx

Following the introduction of CMake'ified python (r21863), python 2.7.3 is
now used. Since developer also have a similar version installed on their
system, this is causing Slicer to crash due to binary incompatibility
between the patched version build by Slicer (r21848) and the one
installed on the system.

While this commit address the immediate issue specific to python, the same
problem would occur with VTK, Qt, ITK or any other Slicer external projects
is already installed in the system. The solution implemented by this commit
will have to be revisited.

See http://www.na-mic.org/Bug/view.php?id=1180
Fixes 0001180

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21943 3bd1e089-480b-0410-8dfb-8563597acbee
mod - Applications/SlicerApp/CMakeLists.txt Diff File

Slicer: 2145-support-for-installing-extension-from-file cc18ef43

2013-04-26 18:17:12

jcfr

Details Diff
COMP: Fix config error introduced in r21943 by using PYTHON_LIBRARY_PATH

See issue 0001180 - http://www.na-mic.org/Bug/view.php?id=1180

git-svn-id: http://svn.slicer.org/Slicer4/trunk@21948 3bd1e089-480b-0410-8dfb-8563597acbee
mod - Applications/SlicerApp/CMakeLists.txt Diff File

Issue History

Date Modified Username Field Change
2011-05-30 13:28 lassoan New Issue
2011-05-30 13:28 lassoan Note Added: 0002464
2011-05-30 13:38 finetjul Priority normal => low
2012-01-19 07:01 gregsharp Note Added: 0003506
2012-02-10 10:24 jcfr Status new => assigned
2012-02-10 10:24 jcfr Assigned To => jcfr
2012-04-25 18:37 jcfr Note Added: 0004082
2012-04-25 18:38 jcfr Note Edited: 0004082
2012-04-26 06:32 lassoan Note Added: 0004085
2012-04-26 06:34 lassoan Note Added: 0004086
2012-06-25 15:45 jcfr File Added: Issue-1180-Python-dll-loaded.png
2012-06-25 15:47 jcfr Note Added: 0004937
2012-06-25 15:47 jcfr Status assigned => resolved
2012-06-25 15:47 jcfr Fixed in Version => Slicer 4.2.0 - Sept 1st 2012
2012-06-25 15:47 jcfr Resolution open => fixed
2012-07-27 15:36 jcfr Note Added: 0005303
2012-07-27 17:24 lassoan Note Added: 0005430
2012-07-27 17:24 lassoan Status resolved => feedback
2012-07-27 17:24 lassoan Resolution fixed => reopened
2012-07-27 18:18 jcfr Status feedback => assigned
2012-08-22 05:42 jcfr Target Version => Slicer 4.2.0 - Feature freeze Sept 1st 2012
2012-09-04 12:17 jcfr Target Version Slicer 4.2.0 - Feature freeze Sept 1st 2012 => Slicer 4.3.0
2012-09-04 12:19 jcfr Note Added: 0005959
2013-04-25 12:08 pieper Note Added: 0008490
2013-04-25 12:21 jcfr Note Added: 0008491
2013-04-25 12:23 jcfr Note Edited: 0008491
2013-04-25 12:25 jcfr Note Edited: 0008491
2013-04-25 12:51 ungi Note Added: 0008492
2013-04-25 13:12 jcfr Note Added: 0008494
2013-04-25 13:20 inorton Note Added: 0008497
2013-04-25 13:47 jcfr Note Added: 0008498
2013-04-25 13:48 ungi Note Added: 0008499
2013-04-25 13:59 jcfr Note Added: 0008500
2013-04-25 14:42 ungi Note Added: 0008502
2013-04-25 14:47 ungi Note Added: 0008503
2013-04-25 14:54 jcfr Note Edited: 0008500
2013-04-25 14:55 jcfr Note Added: 0008504
2013-04-25 15:13 ungi Note Added: 0008506
2013-04-25 15:14 ungi Note Edited: 0008506
2013-04-26 13:19 jcfr Note Added: 0008521
2013-04-26 13:19 jcfr Status assigned => resolved
2013-04-26 13:19 jcfr Fixed in Version Slicer 4.2.0 => Slicer 4.3.0
2013-04-26 13:19 jcfr Resolution reopened => fixed
2013-04-26 14:18 jcfr Note Added: 0008523
2014-03-06 04:53 jcfr Note Added: 0010787
2014-03-06 04:54 jcfr Status resolved => closed
2017-06-07 23:27 jcfr Changeset attached => Slicer 2145-support-for-installing-extension-from-file cc18ef43
2017-06-07 23:27 jcfr Changeset attached => Slicer 2145-support-for-installing-extension-from-file 689851c3
2017-06-07 23:27 jcfr Note Added: 0014646