The pythondir configuration variable controls which Python executable is used. By default, it’s set to py (the Python Launcher for Windows), but you can point it to any Python executable.
For portable setups, use %cd% to reference the current directory. This makes your project folder relocatable:
Copy
Ask AI
rem Python in a subfolder of your projectset pythondir=%cd%\python\python.exerem Python in a sibling folderset pythondir=%cd%\..\python-3.11\python.exerem Python in a fixed relative locationset pythondir=%cd%\tools\python\python.exe
Using %cd% ensures the launcher works regardless of where the project folder is located on the filesystem. This is ideal for distribution or USB drives.
Absolute paths work but are not portable across systems:
Copy
Ask AI
rem Fixed location - not portable!set pythondir=C:\Python311\python.exerem Network locationset pythondir=\\server\shared\python\python.exe
Absolute paths will break if the project is moved to a different location or run on a different computer. Only use absolute paths for system-specific configurations.
When using a portable Python executable (not py or py.exe), the pythonversion setting is ignored.
The launcher automatically detects whether you’re using the py launcher or a direct Python executable:
Copy
Ask AI
rem Uses pythonversion (e.g., py -3.11)set pythondir=pyset pythonversion=3.11rem Ignores pythonversion (direct executable)set pythondir=%cd%\python\python.exeset pythonversion=3.11 rem This is ignored!
From PythonLauncher.bat:62-77, the script checks if the filename is py or py.exe. If not, it sets usepylancher=0 and runs Python directly without version flags.
Portable Python works seamlessly with virtual environments:
Copy
Ask AI
set pythondir=%cd%\python-portable\python.exeset usevenv=1set venvname=pyvenvset installrequirementsfile=1
The virtual environment will be created using the portable Python installation, ensuring complete isolation.
Using usevenv=1 with portable Python creates a truly portable development environment. The entire project, Python runtime, and dependencies are contained in one folder.
When distributing an application with portable Python:
Copy
Ask AI
rem Disable venv for end-user distributionset usevenv=0rem Pre-install all dependencies in the portable Pythonrem or use a frozen venv included in the distributionset pythondir=%cd%\runtime\python\python.exerem Auto-close when doneset autoclosecmd=1rem Start minimized for cleaner UXset minimizedcmd=1rem Disable Python download alert (they have portable Python)set alertifpynotinstalled=0
rem Enable venv for developmentset usevenv=1rem Install requirements automaticallyset installrequirementsfile=1rem Keep window visible for debuggingset minimizedcmd=0set autoclosecmd=0rem Use relative path to portable Pythonset pythondir=%cd%\python\python.exe