Fix: start-librecrawl.bat failed without Python on PATH or with py only

- It detected the py launcher (set PYTHON=py) but never used it, and called
  bare pip and playwright, which only work if "Add Python to PATH" was
  ticked. Use the detected interpreter, a .venv like the .sh, and
  python -m pip / python -m playwright.
- Require Python 3.11+, matching the Docker image.
- Install requirements on every start, so new dependencies arrive.
- Docker: check Compose and that the daemon is running, and stop with a
  message if docker compose up fails, instead of printing "LibreCrawl is
  running!" regardless.
- Pause on errors so a double-clicked window stays open to read them.
This commit is contained in:
phialsbasement committed 2026-11-10 08:20:30 +11:00
1 parent 75d5a36406
commit b4d2e7e3f5
1 file changed
+64 -25
+64 -25
View File
@@ -1,12 +1,16 @@
@echo off
if not exist data mkdir data␍
if not exist data mkdir data
echo Checking for Docker...
docker --version 2>nul
docker compose version >nul 2>&1
if errorlevel 1 goto nodocker
docker info >nul 2>&1
if errorlevel 1 goto dockernotrunning
echo Docker found! Starting LibreCrawl...
docker compose up -d
if errorlevel 1 goto dockerfailed
timeout /t 3 /nobreak >nul
echo.
@@ -24,37 +28,72 @@ docker compose logs -f
docker compose down
exit /b
:dockernotrunning
echo.
echo ERROR: Docker is installed but not running.
echo Start Docker Desktop, wait until it says it is running, then run this again.
echo.
pause
exit /b 1
:dockerfailed
echo.
echo ERROR: Docker could not start LibreCrawl. The messages above say why.
echo.
pause
exit /b 1
:nodocker
echo Docker not found. Checking for Python...
python --version 2>nul
if errorlevel 1 goto trypy
:foundpython
echo Python found! Checking dependencies...
pip show flask 2>nul
if errorlevel 1 goto installdeps
:rundirect
echo Starting LibreCrawl...
start /b cmd /c "timeout /t 2 /nobreak >nul && start http://localhost:5000"
python main.py -l
exit /b
:trypy
py --version 2>nul
if errorlevel 1 goto nopython
set PYTHON=python
python --version >nul 2>&1
if not errorlevel 1 goto checkversion
set PYTHON=py
goto foundpython
py --version >nul 2>&1
if errorlevel 1 goto nopython
:checkversion
rem Python 3.11+, same as the Docker image
%PYTHON% -c "import sys; sys.exit(sys.version_info < (3, 11))" >nul 2>&1
if errorlevel 1 goto nopython
rem Own environment, so LibreCrawl's packages don't touch the system Python
if exist .venv\Scripts\python.exe goto installdeps
echo Creating a Python environment in .venv...
%PYTHON% -m venv .venv
if errorlevel 1 goto venvfailed
:installdeps
echo Installing dependencies...
pip install -r requirements.txt
playwright install chromium
goto rundirect
echo Installing Python packages from requirements.txt...
.venv\Scripts\python -m pip install --quiet -r requirements.txt
if errorlevel 1 goto depsfailed
echo Installing Playwright browser...
.venv\Scripts\python -m playwright install chromium
if errorlevel 1 goto depsfailed
echo Starting LibreCrawl...
start /b cmd /c "timeout /t 2 /nobreak >nul && start http://localhost:5000"
.venv\Scripts\python main.py -l
exit /b
:venvfailed
echo.
echo ERROR: Could not create the Python environment in .venv.
echo.
pause
exit /b 1
:depsfailed
echo.
echo ERROR: Failed to install LibreCrawl's dependencies. The messages above say why.
echo.
pause
exit /b 1
:nopython
echo.
echo ERROR: Neither Docker nor Python found!
echo ERROR: Neither Docker nor Python 3.11+ found!
echo.
echo Please install one of:
echo - Docker Desktop: https://www.docker.com/products/docker-desktop