Skip to content

Commit 5e5d10e

Browse files
authored
Merge pull request #2519 from SCIInstitute/amorris/2518-install
Fix conda env activation after conda init and add installation validation
2 parents 6f3acb4 + b52894e commit 5e5d10e

1 file changed

Lines changed: 112 additions & 6 deletions

File tree

install_shapeworks.sh

Lines changed: 112 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
SW_MAJOR_VERSION=6.7
66

7+
# Set up logging
8+
INSTALL_LOG="install_shapeworks_$(date +%Y%m%d_%H%M%S).log"
9+
exec > >(tee -a "$INSTALL_LOG") 2>&1
10+
echo "Logging to $INSTALL_LOG"
11+
712
echo ""
813
echo "Note: this script only supports bash and zsh shells "
914
echo " It must be called using \"source ./install_shapeworks.sh [--developer] [--user] [optional_env_name]\""
@@ -134,20 +139,44 @@ function install_conda() {
134139

135140
eval "$(conda shell.bash hook)"
136141
if ! conda activate $CONDAENV; then return 1; fi
137-
142+
143+
echo "=== Environment after first activation ==="
144+
echo "CONDA_PREFIX: $CONDA_PREFIX"
145+
echo "which python: $(which python)"
146+
echo "============================================"
147+
138148
# install conda into the shell
139149
conda init
140150

151+
# re-activate after conda init (it can disrupt the environment)
152+
eval "$(conda shell.bash hook)"
153+
conda activate $CONDAENV
154+
155+
echo "=== Environment after re-activation ==="
156+
echo "CONDA_PREFIX: $CONDA_PREFIX"
157+
echo "which python: $(which python)"
158+
echo "PATH: $PATH"
159+
echo "========================================"
160+
141161
if ! python -m pip install -r python_requirements.txt; then return 1; fi
142162

143163
# install pytorch using light-the-torch
164+
# Use python -m to ensure we use the conda env's light_the_torch, not ~/.local/bin/ltt
165+
echo "=== PyTorch installation diagnostics ==="
166+
echo "CONDA_PREFIX: $CONDA_PREFIX"
167+
echo "which python: $(which python)"
168+
echo "python version: $(python --version)"
169+
echo "python sys.executable: $(python -c 'import sys; print(sys.executable)')"
170+
echo "which pip: $(which pip)"
171+
echo "which ltt: $(which ltt)"
172+
echo "========================================="
144173
if [[ $(uname -s) == "Darwin" ]] && [[ $(uname -m) == "x86_64" ]]; then
145174
# Intel Mac - use older versions with NumPy 1.x
146-
if ! ltt install torch==2.2.2 torchaudio==2.2.2 torchvision==0.17.2; then return 1; fi
175+
if ! python -m light_the_torch install torch==2.2.2 torchaudio==2.2.2 torchvision==0.17.2; then return 1; fi
147176
pip install "numpy<2"
148177
else
149178
# Apple Silicon, Linux, Windows - use latest with NumPy 2.x support
150-
if ! ltt install torch==2.8.0 torchaudio==2.8.0 torchvision==0.23.0; then return 1; fi
179+
if ! python -m light_the_torch install torch==2.8.0 torchaudio==2.8.0 torchvision==0.23.0; then return 1; fi
151180
fi
152181

153182
# for network analysis
@@ -237,10 +266,87 @@ if install_conda; then
237266
pip list
238267

239268
conda clean -t -y
240-
241-
echo "$CONDAENV environment successfully created/updated!"
242-
269+
243270
conda activate $CONDAENV
271+
272+
# Validate installation
273+
echo ""
274+
echo "=== Validating installation ==="
275+
VALIDATION_FAILED=0
276+
277+
# Check Python version
278+
PYTHON_VERSION=$(python -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
279+
if [[ "$PYTHON_VERSION" == "3.12" ]]; then
280+
echo "✓ Python version: $PYTHON_VERSION"
281+
else
282+
echo "✗ Python version: $PYTHON_VERSION (expected 3.12)"
283+
VALIDATION_FAILED=1
284+
fi
285+
286+
# Check torch is installed and using correct Python
287+
if python -c "import torch; print(f'✓ torch {torch.__version__} (CUDA: {torch.cuda.is_available()})')" 2>/dev/null; then
288+
TORCH_PATH=$(python -c "import torch; print(torch.__file__)")
289+
if [[ "$TORCH_PATH" == *"$CONDAENV"* ]]; then
290+
echo " installed in conda env: $TORCH_PATH"
291+
else
292+
echo "✗ torch installed in wrong location: $TORCH_PATH"
293+
VALIDATION_FAILED=1
294+
fi
295+
else
296+
echo "✗ torch: failed to import"
297+
VALIDATION_FAILED=1
298+
fi
299+
300+
# Check shapeworks package (may not be available in developer mode until built)
301+
if python -c "import shapeworks; print(f'✓ shapeworks package imported successfully')" 2>/dev/null; then
302+
:
303+
else
304+
if [[ "$DEVELOPER" == "YES" ]]; then
305+
echo "- shapeworks: not yet available (expected in developer mode, will be available after build)"
306+
else
307+
echo "✗ shapeworks: failed to import"
308+
VALIDATION_FAILED=1
309+
fi
310+
fi
311+
312+
# Check DeepSSMUtils (may not be available in developer mode until built)
313+
if python -c "import DeepSSMUtils; print(f'✓ DeepSSMUtils package imported successfully')" 2>/dev/null; then
314+
:
315+
else
316+
if [[ "$DEVELOPER" == "YES" ]]; then
317+
echo "- DeepSSMUtils: not yet available (expected in developer mode, will be available after build)"
318+
else
319+
echo "✗ DeepSSMUtils: failed to import"
320+
VALIDATION_FAILED=1
321+
fi
322+
fi
323+
324+
# Check vtk
325+
if python -c "import vtk; print(f'✓ vtk {vtk.vtkVersion.GetVTKVersion()}')" 2>/dev/null; then
326+
:
327+
else
328+
echo "✗ vtk: failed to import"
329+
VALIDATION_FAILED=1
330+
fi
331+
332+
# Check itk
333+
if python -c "import itk; print(f'✓ itk {itk.Version.GetITKVersion()}')" 2>/dev/null; then
334+
:
335+
else
336+
echo "✗ itk: failed to import"
337+
VALIDATION_FAILED=1
338+
fi
339+
340+
echo "================================"
341+
342+
if [[ "$VALIDATION_FAILED" == "1" ]]; then
343+
echo ""
344+
echo "WARNING: Some validation checks failed. Please review the output above."
345+
else
346+
echo ""
347+
echo "$CONDAENV environment successfully created/updated!"
348+
fi
349+
244350
else
245351
echo "Problem encountered creating/updating $CONDAENV conda environment."
246352
return 1;

0 commit comments

Comments
 (0)