Playwright install-deps error
Hi,I have issue with installing deps for playwright on hf spaces.ERROR:╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Please install them with the following command:      ║
║                                                      ║
║     sudo playwright install-deps                     ║
║                                                      ║
║ Alternatively, use apt:                              ║
║     sudo apt-get install libnss3\                    ║
║         libnspr4\                                    ║
║         libatk1.0-0\                                 ║
║         libatk-bridge2.0-0\                          ║
║         libcups2\                                    ║
║         libatspi2.0-0\                               ║
║         libxcomposite1\                              ║
║         libxdamage1                                  ║
║                                                      ║
║ <3 Playwright Team                                   ║
╚══════════════════════════════════════════════════════╝My Dockerfile:FROM python:3.8

# Install necessary dependencies
RUN apt-get update && apt-get install -y \
    libnss3 \
    libnspr4 \
    libatk1.0-0 \
    libatk-bridge2.0-0 \
    libcups2 \
    libatspi2.0-0 \
    libxcomposite1 \
    libxdamage1 \
    libxrandr2 \
    libgbm-dev \
    libgtk-3-0 \
    xdg-utils \
    && rm -rf /var/lib/apt/lists/*

# Install Playwright and other dependencies
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN playwright install --with-deps

# Utwórz użytkownika i ustaw katalog roboczy
RUN useradd -m -u 1000 user
USER user
WORKDIR /code

# Skopiuj plik requirements.txt i zainstaluj zależności Pythona
COPY --chown=user:user requirements.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt

# Skopiuj resztę aplikacji
COPY --chown=user:user . /code

# Ustawienie punktu wejścia dla aplikacji
CMD ["python", "app.py"]I try also this in code:# Initialize Playwright
os.system("playwright install")

import subprocess

def install_playwright_and_deps():
    try:
        # Instalacja Playwright
        subprocess.check_call(["pip", "install", "playwright"])
        # Instalacja przeglądarek Playwright
        subprocess.check_call(["apt-get", "playwright", "install-deps"])
    except subprocess.CalledProcessError as e:
        print(f"Error installing Playwright or dependencies: {e}")

install_playwright_and_deps()Nothing help only I get a message about:t validateDependenciesLinux (/usr/local/lib/python3.10/site-packages/playwright/driver/package/lib/server/registry/dependencies.js:216:9)at async Registry._validateHostRequirements (/usr/local/lib/python3.10/site-packages/playwright/driver/package/lib/server/registry/index.js:575:43)at async Registry._validateHostRequirementsForExecutableIfNeeded (/usr/local/lib/python3.10/site-packages/playwright/driver/package/lib/server/registry/index.js:673:7)at async Registry.validateHostRequirementsForExecutablesIfNeeded (/usr/local/lib/python3.10/site-packages/playwright/driver/package/lib/server/registry/index.js:662:43)at async t. (/usr/local/lib/python3.10/site-packages/playwright/driver/package/lib/cli/program.js:119:7)Requirement already satisfied: playwright in /usr/local/lib/python3.10/site-packages (1.45.1)Requirement already satisfied: greenlet==3.0.3 in /usr/local/lib/python3.10/site-packages (from playwright) (3.0.3)Requirement already satisfied: pyee==11.1.0 in /usr/local/lib/python3.10/site-packages (from playwright) (11.1.0)Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/site-packages (from pyee==11.1.0->playwright) (4.12.2)[notice] A new release of pip available: 22.3.1 → 24.2[notice] To update, run: pip install --upgrade pipE: Invalid operation playwrightError installing Playwright or dependencies: Command ‘[‘apt-get’, ‘playwright’, ‘install-deps’]’ returned non-zero exit status 100.Running on local URL:http://0.0.0.0:7860I dont have any other idea…ChatGPT also didnt help much more than thisMaybe someone had more exp. with spaces and see an obviouse error that I made here
2024-08-15T10:26:12Z
I fix it with  and run headless = True (very important)# Install Python dependencies
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt

# Install Playwright and download the required browsers
RUN playwright install --with-deps

# Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Ensure Playwright browsers are installed for the non-root user
RUN playwright install
2024-08-15T13:21:41Z
Sorry I don’t know much about Docker since I use Gradio all the time, but you can use packages.txt and pre-requirements.txt in addition to requiements.txt in HF’s Spaces.Can’t you do something about this?huggingface.corequirements.txt · r3gm/DiffuseCraft at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.huggingface.copre-requirements.txt · John6666/text2tag-llm at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.huggingface.copackages.txt · r3gm/DiffuseCraft at mainWe’re on a journey to advance and democratize artificial intelligence through open source and open science.As a last resort, some people call subprocess in the py file to launch the installer.
2024-08-15T16:49:06Z
Thanks for your answer! Fortunately I was able to fix it as I wrote above mainly I think because of this:# Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Ensure Playwright browsers are installed for the non-root user
RUN playwright install