Skip to content

Instantly share code, notes, and snippets.

@hack-r
Created June 11, 2023 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hack-r/7196acddb96f6ca57e2753b756ba5ece to your computer and use it in GitHub Desktop.
Save hack-r/7196acddb96f6ca57e2753b756ba5ece to your computer and use it in GitHub Desktop.
#!/bin/zsh
# Name of the original requirements file
original_file="requirements.txt"
# Backup the original requirements file
cp "$original_file" "${original_file}.bak"
# Read the packages from requirements.txt and install them using pip
while read -r package; do
echo "Installing $package"
pip install "$package"
result=$?
if [ $result -ne 0 ]; then
# Error occurred, remove the version number specification for the package
package_name="${package%%=*}"
sed -i '' "/^$package_name==/d" "$original_file"
echo "Error occurred while installing $package, version number removed from $original_file"
echo "Retrying installation without version number"
pip install -r "$original_file"
fi
done <"$original_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment