Skip to content

Improve download_from_zenodo.sh to auto-detect python3 or python on Windows #2

@pietroluigiwilli

Description

@pietroluigiwilli

On Windows (Git Bash), the download_from_zenodo.sh script previously assumed python3 was available. If python3 was not installed or not on PATH, the script stopped after:

✓ Connected to Zenodo record: 18357418

because the first call to python3 inside the loop failed, and set -e caused an early exit. This made the script appear to “hang” or silently stop for users without python3.

I’ve added a small detection block near the top of the script to make it more robust across platforms:

# Determine which Python to use
if command -v python3 >/dev/null 2>&1; then
    PYTHON_CMD=python3
elif command -v python >/dev/null 2>&1; then
    PYTHON_CMD=python
else
    echo "❌ Failed to find a Python interpreter (python3 or python)."
    exit 1
fi

Then all inline Python calls use "$PYTHON_CMD" instead of hardcoding python3:

download_url=$(echo "$FILES_JSON" | "$PYTHON_CMD" -c "
import sys, json
data = json.load(sys.stdin)
for f in data.get('files', []):
    if f.get('key') == '${zenodo_name}':
        print(f['links']['self'])
        break
" 2>/dev/null)

This allows the script to work on systems with only python installed, while still preferring python3 when available, and fails fast with a clear error message if no Python interpreter is found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions