From 3e37854445aa2da5c885a1122192e0b383965546 Mon Sep 17 00:00:00 2001 From: Florez Ospina Juan Felipe Date: Wed, 4 Dec 2024 16:15:42 +0100 Subject: [PATCH] Solved binary incompatibility issue of generated environment by conda installing h5py and numpy from conda-forge or default channels. --- environment.yml | 5 +++-- setup_env.sh | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/environment.yml b/environment.yml index e3ea0d4..2051f5c 100644 --- a/environment.yml +++ b/environment.yml @@ -1,5 +1,5 @@ name: pyenv5505 -prefix: ./envs/pyenv5505 # Custom output folder +#prefix: ./envs/pyenv5505 # Custom output folder channels: - conda-forge - defaults @@ -7,6 +7,7 @@ dependencies: - python=3.11 - jupyter - numpy + - h5py - pandas - matplotlib - plotly=5.24 @@ -14,7 +15,7 @@ dependencies: - sphinx - pip - pip: - - h5py==3.10 +# - h5py==3.10 - pybis==1.35 - igor2 - ipykernel diff --git a/setup_env.sh b/setup_env.sh index d5cb78e..71e731c 100644 --- a/setup_env.sh +++ b/setup_env.sh @@ -1,8 +1,7 @@ #!/bin/bash -# Define the name and location of the environment +# Define the name of the environment ENV_NAME="pyenv5505" -ENV_PATH="./envs/$ENV_NAME" # Define a custom output folder # Check if mamba is available and use it instead of conda for faster installation if command -v mamba &> /dev/null; then @@ -11,19 +10,38 @@ else CONDA_COMMAND="conda" fi -# Create the conda environment with all dependencies -$CONDA_COMMAND create -y -p "$ENV_PATH" python=3.11 \ - jupyter numpy pandas matplotlib plotly=5.24 scipy pip +# Create the conda environment with all dependencies, resolving from conda-forge and defaults +$CONDA_COMMAND create -y -n "$ENV_NAME" -c conda-forge -c defaults python=3.11 \ + jupyter numpy h5py pandas matplotlib plotly=5.24 scipy pip + +# Check if the environment was successfully created +if [ $? -ne 0 ]; then + echo "Failed to create the environment '$ENV_NAME'. Please check the logs above for details." + exit 1 +fi # Activate the new environment -source activate "$ENV_PATH" || conda activate "$ENV_PATH" +if source activate "$ENV_NAME" 2>/dev/null || conda activate "$ENV_NAME" 2>/dev/null; then + echo "Environment '$ENV_NAME' activated successfully." +else + echo "Failed to activate the environment '$ENV_NAME'. Please check your conda setup." + exit 1 +fi -# Install pip packages in one go to avoid repeated initializations -pip install h5py==3.10 pybis==1.35 igor2 ipykernel sphinx +# Install additional pip packages only if the environment is activated +echo "Installing additional pip packages..." +pip install pybis==1.35 igor2 ipykernel sphinx -# Export the environment to a YAML file -$CONDA_COMMAND env export --prefix "$ENV_PATH" > "$ENV_PATH/environment.yaml" +# Check if pip installations were successful +if [ $? -ne 0 ]; then + echo "Failed to install pip packages. Please check the logs above for details." + exit 1 +fi + +# Optional: Export the environment to a YAML file (commented out) +# $CONDA_COMMAND env export -n "$ENV_NAME" > "$ENV_NAME-environment.yaml" # Print success message -echo "Environment '$ENV_NAME' created successfully at '$ENV_PATH'." -echo "Environment configuration saved to '$ENV_PATH/environment.yaml'." +echo "Environment '$ENV_NAME' created and configured successfully." +# echo "Environment configuration saved to '$ENV_NAME-environment.yaml'." +