Python Manager
Overview
Section titled “Overview”The Python Manager LOP simplifies managing external Python libraries within TouchDesigner. It allows you to create isolated Python environments (virtual environments) for your projects, install packages using pip
or from Git repositories, and run Python scripts or shell commands without interfering with TouchDesigner’s core Python installation.
This ensures that project-specific dependencies don’t cause conflicts across different TouchDesigner projects or with the base TouchDesigner Python environment.
Key Concepts
Section titled “Key Concepts”Virtual Environments (venv)
Section titled “Virtual Environments (venv)”A virtual environment is an isolated directory containing a specific Python version and its own set of installed packages.
- Isolation: Packages installed in a
venv
are only available when that environment is active or added to the project’s path. This prevents conflicts between different projects that might require different versions of the same library. - Project-Specific: You typically create one
venv
per project (or group of related projects) in a designatedBase Folder
. - Activation: The Python Manager handles adding the
venv
’ssite-packages
directory (where libraries are installed) to your TouchDesigner project’ssys.path
, making the installed libraries importable.
Python Version Requirement
Section titled “Python Version Requirement”Usage in LOPS
Section titled “Usage in LOPS”Many LOPS operators (like Florence, OCR, RAG Index, etc.) rely on external Python libraries that require specific versions or CUDA dependencies (e.g., PyTorch). These operators automatically use the Python Manager instance located within the ChatTD
LOP (/tox/ChatTD/python_manager
) to manage these dependencies.
You typically do not need to interact directly with the Python Manager for these LOPS dependencies. Here’s how it works:
- Requirement Check: When a LOP initializes or runs, it checks if its required Python libraries (like
torch
,transformers
) are available in the environment managed byChatTD
’s Python Manager. - Installation Prompt: If requirements are missing, the LOP will trigger the Python Manager to display a pop-up dialog. This dialog will inform you which packages need to be installed (e.g., “PyTorch 2.1.1 with CUDA 11.8/12.1 support”).
- User Confirmation: You will be asked to confirm the installation or select options (like the CUDA version for PyTorch).
- Managed Installation: Upon confirmation, the Python Manager handles the download and installation process within its designated virtual environment. TouchDesigner might pause during this process.
- Completion: Once installed, the LOP can import and use the libraries.
This automated process ensures that complex dependencies like PyTorch (with specific CUDA versions compatible with TouchDesigner’s Python version) are installed correctly without manual intervention via the Python Manager interface.
Basic Workflow (Standalone Usage)
Section titled “Basic Workflow (Standalone Usage)”While LOPS manage their own dependencies, you can also use the Python Manager standalone to manage libraries for your custom tools or general project needs. The video tutorial above provides a great walkthrough. The basic steps are:
- Select Python: Ensure the correct Python 3.11 executable is selected on the
Python Setup
page (usually auto-detected). - Set Base Folder: Choose or create a folder where the virtual environment will reside using the
Base Folder
parameter. - Create venv: Pulse the
Create venv
parameter. A command window might briefly appear. - Add to Path: Pulse
Add venv to sys.path
to make the environment’s packages available to your current TD project. UseAuto Add onStart
orAuto Add onCreate
for convenience in the future. - Install Packages: Use the
Pip
orGit
pages to install the libraries you need into the created virtual environment.
Parameter Reference
Section titled “Parameter Reference”Parameters are organized into pages mirroring the operator’s interface.
op('python_manager').par.Status
Str - Default:
None
op('python_manager').par.Setpython
Pulse - Default:
None
op('python_manager').par.Pythonexe
File - Default:
None
op('python_manager').par.Custompython
Toggle - Default:
on
op('python_manager').par.Createvenv
Pulse - Default:
None
op('python_manager').par.Basefolder
Folder - Default:
None
op('python_manager').par.Openvenv
Pulse - Default:
None
op('python_manager').par.Addtosyspath
Pulse - Default:
None
op('python_manager').par.Addonstart
Toggle - Default:
on
op('python_manager').par.Addoncreate
Toggle - Default:
on
op('python_manager').par.Printpythoninfo
Pulse - Default:
None
op('python_manager').par.Printsyspath
Pulse - Default:
None
op('python_manager').par.Pipinstall
Pulse - Default:
None
op('python_manager').par.Pipupdate
Pulse - Default:
None
op('python_manager').par.Pipuninstall
Pulse - Default:
None
op('python_manager').par.Pipinstallfromlist
Pulse - Default:
None
op('python_manager').par.Listinstalledpackages
Pulse - Default:
None
op('python_manager').par.Currentpackages
Str - Default:
0 installed packages
op('python_manager').par.Createreqtxt
Pulse - Default:
None
op('python_manager').par.Upgradepip
Pulse - Default:
None
op('python_manager').par.Gitfolder
Folder - Default:
None
op('python_manager').par.Clonegitrepo
Pulse - Default:
None
op('python_manager').par.Gitrepourl
Str - Default:
None
op('python_manager').par.Installafterclone
Toggle - Default:
off
op('python_manager').par.Showcmdwindow
Toggle - Default:
on
op('python_manager').par.Blockthread
Toggle - Default:
on
op('python_manager').par.Runpythonscript
Pulse - Default:
None
op('python_manager').par.Pyscript
Str - Default:
None
op('python_manager').par.Runshellcommand
Pulse - Default:
None
op('python_manager').par.Shellcmd
Str - Default:
None
op('python_manager').par.Txheader
Str - Default:
python manager - TD Tool by Dotsimulate
op('python_manager').par.Txversion
Str - Default:
1.1.0
op('python_manager').par.Txdate
Str - Default:
11/06/2024
op('python_manager').par.Txopenaboutme
Pulse - Default:
None
op('python_manager').par.Viewreadme
Pulse - Default:
None
op('python_manager').par.Clearlogonstart
Toggle - Default:
on
op('python_manager').par.Popups
Toggle - Default:
off
op('python_manager').par.Showbuiltin
Toggle - Default:
off
Technical Notes
Section titled “Technical Notes”- Python 3.11: Requires an external installation of Python 3.11.x.
git
Requirement: Cloning Git repositories requiresgit
to be installed on your system and accessible via the command line (in the system’s PATH).sys.path
: Adding the venv tosys.path
only affects the current TouchDesigner process. Use theAuto Add onStart
parameter for persistence across project restarts.- Background Tasks: Be mindful when disabling
Block TD Thread
. While it keeps TD responsive, subsequent operations that depend on the background task completing might fail if initiated too early.
Related Operators
Section titled “Related Operators”- ChatTD: Often contains the primary Python Manager instance used by other LOPS.