ok this is certainly a slightly annoying problem!
1. installation
the commands to install on linux are below.
wget -P ~/ElastixDownload "https://github.com/SuperElastix/elastix/releases/download/5.0.1/elastix-5.0.1-linux.tar.bz2"
tar -xvf elastix-5.0.1-linux.tar.bz2
to actually use these in a shell, you have to update the path (and the exact installation directory may differ slightly on github:
export Path=$Path:~/ElastixDownload/elastix-5.0.1-linux/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/ElastixDownload/elastix-5.0.1-linux/lib/
Note that this updates the path ONCE in the terminal it is entered, not forever.
if you want to always have this path update, you could edit your bashrc file which contains a list of things that happen every time a terminal is open
nano ~/.bashrc
# then copy this somewhere in the file:
export Path=$Path:~/ElastixDownload/elastix-5.0.1-linux/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/ElastixDownload/elastix-5.0.1-linux/lib/
this you already pretty much figure out, albeit some of the steps were commented out (but I assume this was just debugging)
the issue as it turns out is setting the environment for a command to be executed in linux:
2. calling from inside python
When you start a new process inside python, it launches in a fresh terminal.
so if you have done the .bashrc step, I think the python commands should work (haven't checked this).
If you have not edited the bashrc file, then you can also change the environment a process launches in. so you can replace the test_ElastixInstalled
test with something like the following and it should run:
def test_ElastixInstalled():
home_dir = Path(os.path.expanduser('~')) # may have to update for github system
elastix_dir = home_dir / 'ElastixDownload' / 'elastix-5.0.1-linux' / 'bin'
elastix_lib_dir = home_dir / 'ElastixDownload' / 'elastix-5.0.1-linux' / 'lib'
my_env = os.environ.copy()
my_env["PATH"] = my_env["PATH"] + ':' + str(elastix_dir)
my_env["LD_LIBRARY_PATH"] = my_env["LD_LIBRARY_PATH"] + ':' + str(elastix_lib_dir)
bashCommand = "/home/brendan/ElastixDownload/elastix-5.0.1-linux/bin/elastix -h"
subprocess.Popen(bashCommand.split(), env=my_env)