I'm trying to install Open WebUI as a portable installation, where the base folder can be moved or renamed. However, I've encountered issues making the virtual environment truly portable.
While installing, I've tried using dynamic paths, but somehow the paths get hardcoded during the installation process. When I try to activate the virtual environment in a different location, I receive an error:
Fatal error in launcher: Unable to create process using '"...original\path\venv\Scripts\python.exe" "...new\path\venv\Scripts\open-webui.exe" serve': The system cannot find the file specified.
How can I solve this issue and make my pip virtual environments truly portable?
In this example I'm using two batch files to install Open WebUI.
setup.bat
@echo on
REM setup.bat - Run this first to create the Open-WebUI_portable environment
set BASE_DIR=%~dp0
set VENV_DIR=%BASE_DIR%venv
set PYTHON_DIR=%BASE_DIR%python
set PIP_DIR=%BASE_DIR%pip-cache
set APPDATA=%BASE_DIR%appdata
set USERPROFILE=%BASE_DIR%userprofile
set HOME=%BASE_DIR%home
set XDG_CACHE_HOME=%BASE_DIR%cache
set PYTHONUSERBASE=%BASE_DIR%pythonuser
echo Creating directories...
mkdir "%PIP_DIR%" 2>nul
mkdir "%APPDATA%" 2>nul
mkdir "%USERPROFILE%" 2>nul
mkdir "%HOME%" 2>nul
mkdir "%XDG_CACHE_HOME%" 2>nul
mkdir "%PYTHONUSERBASE%" 2>nul
:DOWNLOAD_PYTHON
echo Downloading Python...
curl -L "https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip" -o "%BASE_DIR%python.zip"
if not exist "%BASE_DIR%python.zip" (
echo ERROR: Failed to download Python
echo Would you like to retry? (Y/N^)
choice /c yn /n
if errorlevel 2 (
echo Installation cancelled
exit /b 1
)
goto DOWNLOAD_PYTHON
)
echo Extracting Python...
powershell -Command "Expand-Archive -Path '%BASE_DIR%python.zip' -DestinationPath '%PYTHON_DIR%' -Force"
if not exist "%PYTHON_DIR%\python.exe" (
echo ERROR: Failed to extract Python
pause
exit /b 1
)
echo Configuring Python for pip...
del "%PYTHON_DIR%\python311._pth" 2>nul
(
echo python311.zip
echo .
echo %PYTHON_DIR%\Lib\site-packages
echo .
echo import site
) > "%PYTHON_DIR%\python311._pth"
:DOWNLOAD_GETPIP
echo Downloading get-pip.py...
curl -L "https://bootstrap.pypa.io/get-pip.py" -o "%BASE_DIR%get-pip.py"
if not exist "%BASE_DIR%get-pip.py" (
echo ERROR: Failed to download get-pip.py
echo You can try to download it manually from https://bootstrap.pypa.io/get-pip.py
echo and place it in %BASE_DIR%get-pip.py
echo.
echo Would you like to retry the download? (Y/N^)
choice /c yn /n
if errorlevel 2 (
echo Installation cancelled
exit /b 1
)
goto DOWNLOAD_GETPIP
)
echo Installing pip...
"%PYTHON_DIR%\python.exe" "%BASE_DIR%get-pip.py" --no-warn-script-location
if errorlevel 1 (
echo ERROR: Failed to install pip
echo This is a critical error. Please ensure:
echo 1. You have internet connection
echo 2. Any antivirus is not blocking the installation
echo 3. You are running this script as administrator
pause
exit /b 1
)
echo Installing virtualenv...
"%PYTHON_DIR%\Scripts\pip.exe" install virtualenv
if errorlevel 1 (
echo ERROR: Failed to install virtualenv
echo This is a critical error. Please check your internet connection
pause
exit /b 1
)
echo Creating virtual environment...
"%PYTHON_DIR%\Scripts\virtualenv.exe" "%VENV_DIR%"
if not exist "%VENV_DIR%\Scripts\activate.bat" (
echo ERROR: Failed to create virtual environment
pause
exit /b 1
)
echo Installing Open WebUI...
call "%VENV_DIR%\Scripts\activate.bat"
"%VENV_DIR%\Scripts\pip.exe" install --cache-dir="%PIP_DIR%" open-webui
if errorlevel 1 (
echo ERROR: Failed to install Open WebUI
pause
exit /b 1
)
echo Creating postactivate script for relocatable paths...
mkdir "%VENV_DIR%\Scripts\postactivate.d" 2>nul
(
echo @echo on
echo set BASE_DIR=%%~dp0
echo set APPDATA=%%BASE_DIR%%appdata
echo set LOCALAPPDATA=%%BASE_DIR%%localappdata
echo set USERPROFILE=%%BASE_DIR%%userprofile
echo set HOME=%%BASE_DIR%%home
echo set XDG_CACHE_HOME=%%BASE_DIR%%cache
echo set XDG_CONFIG_HOME=%%BASE_DIR%%config
echo set PYTHONUSERBASE=%%BASE_DIR%%pythonuser
echo set PIP_CACHE_DIR=%%BASE_DIR%%pip-cache
echo set TEMP=%%BASE_DIR%%temp
echo set TMP=%%BASE_DIR%%temp
) > "%VENV_DIR%\Scripts\postactivate.d\relocatable.bat"
echo Cleaning up...
del "%BASE_DIR%python.zip"
del "%BASE_DIR%get-pip.py"
echo Setup complete! Use run.bat to start Open WebUI
pause
and run.bat
@echo on
set BASE_DIR=%~dp0
set VENV_DIR=%BASE_DIR%venv
REM Set all environment variables to keep files in Open-WebUI_portable directory
set APPDATA=%BASE_DIR%appdata
set LOCALAPPDATA=%BASE_DIR%localappdata
set USERPROFILE=%BASE_DIR%userprofile
set HOME=%BASE_DIR%home
set XDG_CACHE_HOME=%BASE_DIR%cache
set XDG_CONFIG_HOME=%BASE_DIR%config
set PYTHONUSERBASE=%BASE_DIR%pythonuser
set PIP_CACHE_DIR=%BASE_DIR%pip-cache
set TEMP=%BASE_DIR%temp
set TMP=%BASE_DIR%temp
REM Create necessary directories
mkdir "%APPDATA%" 2>nul
mkdir "%LOCALAPPDATA%" 2>nul
mkdir "%USERPROFILE%" 2>nul
mkdir "%HOME%" 2>nul
mkdir "%XDG_CACHE_HOME%" 2>nul
mkdir "%XDG_CONFIG_HOME%" 2>nul
mkdir "%PYTHONUSERBASE%" 2>nul
mkdir "%TEMP%" 2>nul
REM Activate virtual environment
call "%VENV_DIR%\Scripts\activate.bat"
REM Run postactivate script for relocatable paths
call "%VENV_DIR%\Scripts\postactivate.d\relocatable.bat"
REM Run Open WebUI
"%VENV_DIR%\Scripts\open-webui.exe" serve
REM Open browser to localhost:8080
start "" http://localhost:8080
pause
It initially works fine, but when I rename or move the base folder it stops working. Error:
F:\OpenWebUI-portable-NEW>call "F:\OpenWebUI-portable-NEW\venv\Scripts\activate.bat"
Fatal error in launcher: Unable to create process using '"F:\OpenWebUI-portable-OLD\venv\Scripts\python.exe" "F:\OpenWebUI-portable-NEW\venv\Scripts\open-webui.exe" serve': The system cannot find the file specified.
so far the only workaround is to create offline portable project folder like this: In case of after moving or renaming when the project folder stops working, do the following:
telemetry_user_id
, webui.db
, vector_db
, uploads
setup.bat
telemetry_user_id
, webui.db
, vector_db
, uploads
run.bat