File size: 3,733 Bytes
eb09c29 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
#!/bin/bash
# Script to fix numpy availability issue in Video Action Recognition
# This script handles the directory with spaces in the name
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Video Action Recognition - Numpy Fix Script"
echo "============================================"
echo "Working directory: $SCRIPT_DIR"
echo ""
# Check if we're in the right directory
if [[ ! -f "$SCRIPT_DIR/requirements.txt" ]]; then
echo "β Error: requirements.txt not found"
echo "Make sure you're running this script from the Video Action Recognition directory"
exit 1
fi
# Check if virtual environment exists
if [[ ! -d "$SCRIPT_DIR/.venv" ]]; then
echo "β Error: Virtual environment not found"
echo "Creating virtual environment..."
cd "$SCRIPT_DIR"
python3 -m venv .venv
if [[ $? -ne 0 ]]; then
echo "β Failed to create virtual environment"
exit 1
fi
echo "β
Virtual environment created"
fi
# Activate virtual environment
echo "Activating virtual environment..."
source "$SCRIPT_DIR/.venv/bin/activate"
if [[ "$VIRTUAL_ENV" == "" ]]; then
echo "β Failed to activate virtual environment"
exit 1
fi
echo "β
Virtual environment activated: $VIRTUAL_ENV"
# Upgrade pip first
echo ""
echo "Upgrading pip..."
python -m pip install --upgrade pip
# Check current numpy status
echo ""
echo "Checking current numpy status..."
python -c "import numpy; print(f'β
Numpy version: {numpy.__version__}')" 2>/dev/null
NUMPY_STATUS=$?
if [[ $NUMPY_STATUS -eq 0 ]]; then
echo "β
Numpy is already working"
else
echo "β Numpy not available, fixing..."
# Force reinstall numpy
echo "Force reinstalling numpy..."
python -m pip install --force-reinstall --no-cache-dir "numpy>=1.24.0"
# Install other dependencies
echo "Installing/updating other dependencies..."
python -m pip install --upgrade "Pillow>=10.0.0"
python -m pip install --upgrade "opencv-python>=4.9.0"
# Install all requirements
echo "Installing from requirements.txt..."
python -m pip install -r "$SCRIPT_DIR/requirements.txt"
fi
# Final test
echo ""
echo "Testing final configuration..."
python -c "
try:
import numpy as np
print(f'β
Numpy: {np.__version__}')
import torch
print(f'β
PyTorch: {torch.__version__}')
from PIL import Image
print('β
PIL: Available')
import cv2
print(f'β
OpenCV: {cv2.__version__}')
from transformers import AutoImageProcessor
print('β
Transformers: Available')
# Test the specific numpy operations used in video processing
test_array = np.array([[[1, 2, 3], [4, 5, 6]]], dtype=np.float32)
stacked = np.stack([test_array, test_array], axis=0)
print(f'β
Numpy operations work: shape {stacked.shape}')
print('')
print('π All dependencies are working correctly!')
except Exception as e:
print(f'β Error: {e}')
print('')
print('β Some dependencies are still not working')
exit(1)
"
if [[ $? -eq 0 ]]; then
echo ""
echo "β
Fix completed successfully!"
echo ""
echo "You can now run your app with:"
echo " source .venv/bin/activate"
echo " streamlit run app.py"
echo ""
echo "Or use the run script:"
echo " ./run_app.sh"
else
echo ""
echo "β Issues remain. Try these additional steps:"
echo "1. Delete and recreate the virtual environment:"
echo " rm -rf .venv"
echo " python3 -m venv .venv"
echo " source .venv/bin/activate"
echo " pip install -r requirements.txt"
echo ""
echo "2. Check your Python installation"
echo "3. Try using a different Python version"
fi
|