#!/bin/bash

sudo apt update
sudo apt upgrade
sudo apt install python3.11
sudo apt install python3.11-venv

# Name of the virtual environment
VENV_DIR="/usr/bin/my_venv"

# Check if Python 3 is installed
if ! command -v python3 &> /dev/null; then
    echo "Error: Python 3 is not installed. Please install Python 3 first."
    exit 1
fi

# Check if the 'venv' module is available
if ! python3 -m venv --help &> /dev/null; then
    echo "Error: Python 'venv' module is not installed. Please install it."
    exit 1
fi

# Create the virtual environment
echo "Creating a virtual environment in $VENV_DIR..."
python3 -m venv "$VENV_DIR"

if [ $? -eq 0 ]; then
    echo "Virtual environment created successfully."
else
    echo "Error: Failed to create the virtual environment."
    exit 1
fi

# Activate the virtual environment
echo "Activating the virtual environment..."
source "$VENV_DIR/bin/activate"

if [ $? -eq 0 ]; then
    echo "Virtual environment activated successfully."
else
    echo "Error: Failed to activate the virtual environment."
    exit 1
fi

# Upgrade pip in the virtual environment
echo "Upgrading pip..."
pip install --upgrade pip

if [ $? -eq 0 ]; then
    echo "Pip upgraded successfully."
else
    echo "Error: Failed to upgrade pip."
    exit 1
fi

echo "Python virtual environment is ready to use."
echo "To activate it later, run: source $VENV_DIR/bin/activate"



