pathScripts/getreq

37 lines
923 B
Bash
Executable file

#!/bin/bash
# Script to find Python imports and install them if necessary
# Check for input argument
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <path-to-python-file>"
exit 1
fi
PYTHON_FILE="$1"
# Extract import statements
IMPORTS=$(grep -E "^import |^from " "$PYTHON_FILE" | \
awk '{print $2}' | cut -d. -f1 | sort | uniq)
# Function to check and install packages
check_and_install() {
PACKAGE=$1
# Check if the package is installed via pip
if pip list | grep -q "^$PACKAGE "; then
echo "$PACKAGE is already installed via pip."
# Check if the package is installed via conda
elif conda list | grep -q "^$PACKAGE "; then
echo "$PACKAGE is already installed via conda."
else
# Install the package using kip
echo "Installing $PACKAGE using kip..."
kip install "$PACKAGE"
fi
}
# Iterate over imports and check/install them
for pkg in $IMPORTS; do
check_and_install $pkg
done