fix: use venv instead of pip install --user

- Remove automatic Python installation - user must have Python 3.11+ in image
- Use virtual environment (~/.open-webui-venv) to avoid externally-managed-environment error
- Add set -e to fail script on errors
- Update README with installation instructions
This commit is contained in:
Marcin Tojek 2025-12-03 11:42:17 +00:00
parent 25636524d3
commit 6e94ecc165
2 changed files with 27 additions and 35 deletions

View File

@ -14,15 +14,16 @@ This module installs and runs Open WebUI using Python and pip within your Coder
## Prerequisites ## Prerequisites
- **Python 3.11 or higher** (automatically installed from [deadsnakes PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa) if not present) - **Python 3.11 or higher** must be installed in your image (with `venv` module)
- `pip` package manager
- `sudo` access (for automatic Python installation if needed)
- Port 7800 (default) or your custom port must be available - Port 7800 (default) or your custom port must be available
**Note:** If Python 3.11+ is not found, the module will automatically: For Ubuntu/Debian, you can install Python 3.11 from [deadsnakes PPA](https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa):
1. Add the deadsnakes PPA repository
2. Install Python 3.11 with venv and dev packages ```shell
3. Install pip if not available sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install -y python3.11 python3.11-venv
```
## Basic Usage ## Basic Usage

View File

@ -1,4 +1,5 @@
#!/usr/bin/env sh #!/usr/bin/env sh
set -e
# shellcheck disable=SC2059 # shellcheck disable=SC2059
printf '\033[0;1mInstalling Open WebUI...\n\n' printf '\033[0;1mInstalling Open WebUI...\n\n'
@ -29,40 +30,30 @@ for cmd in python3.13 python3.12 python3.11 python3 python; do
done done
if [ -z "$PYTHON_CMD" ]; then if [ -z "$PYTHON_CMD" ]; then
echo "❌ Python 3.11 or higher is not installed" echo "❌ Python 3.11 or higher is required but not found."
echo "" echo ""
echo "Installing Python 3.11 from deadsnakes PPA..." echo "Please install Python 3.11+ in your image. For example on Ubuntu/Debian:"
echo " sudo add-apt-repository -y ppa:deadsnakes/ppa"
# Check if we have sudo access echo " sudo apt-get update"
if ! command -v sudo > /dev/null 2>&1; then echo " sudo apt-get install -y python3.11 python3.11-venv"
echo "❌ sudo is not available. Please install Python 3.11+ manually"
exit 1 exit 1
fi
# Install Python 3.11
echo "📦 Adding deadsnakes PPA..."
sudo apt-get update -qq
sudo apt-get install -y software-properties-common
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get update -qq
echo "📦 Installing Python 3.11..."
sudo apt-get install -y python3.11 python3.11-venv python3.11-dev
PYTHON_CMD="python3.11"
echo "✅ Python 3.11 installed successfully"
fi fi
# Check if pip is available # Set up virtual environment
if ! "$PYTHON_CMD" -m pip --version > /dev/null 2>&1; then VENV_DIR="$HOME/.open-webui-venv"
echo "📦 Installing pip..." if [ ! -d "$VENV_DIR" ]; then
curl -sS https://bootstrap.pypa.io/get-pip.py | "$PYTHON_CMD" echo "📦 Creating virtual environment..."
"$PYTHON_CMD" -m venv "$VENV_DIR"
fi fi
# Activate virtual environment
# shellcheck disable=SC1091
. "$VENV_DIR/bin/activate"
# Check if open-webui is already installed # Check if open-webui is already installed
if ! "$PYTHON_CMD" -m pip show open-webui > /dev/null 2>&1; then if ! pip show open-webui > /dev/null 2>&1; then
echo "📦 Installing Open WebUI..." echo "📦 Installing Open WebUI..."
"$PYTHON_CMD" -m pip install --user open-webui pip install open-webui
echo "🥳 Open WebUI has been installed" echo "🥳 Open WebUI has been installed"
else else
echo "✅ Open WebUI is already installed" echo "✅ Open WebUI is already installed"
@ -78,7 +69,7 @@ echo "👷 Starting Open WebUI in background..."
echo "Check logs at $LOG_PATH" echo "Check logs at $LOG_PATH"
# Start Open WebUI # Start Open WebUI
"$PYTHON_CMD" -m open_webui serve --host 0.0.0.0 --port "$PORT" > "$LOG_PATH" 2>&1 & open-webui serve --host 0.0.0.0 --port "$PORT" > "$LOG_PATH" 2>&1 &
# Wait a bit for the server to start # Wait a bit for the server to start
sleep 2 sleep 2