Installing Python Modules to a TouchDesigner-specific Path

Got a question the other day about how to install packages to other than the default Python site-packages folder* — I have to reconstruct this every time I do it but a really simple method:

pip install --target=/path/to/your/packages/directory/for/TD package_to_install

… and then just point Touch to that path for your Python 64-bit module search path in the prefs. It’s probably a good idea to have a dependencies folder in the same directory as each project (see below).

  • this is Good Practice - generally it’s a Bad Idea to install anything to your system Python as then you have no idea what your dependencies are when you go to move a project to another system. Also updates can break old projects.

I’ve done a version of this with virtualenv and am trying to figure out how I did that (there’s a flag for virtualenv that tells it to install dependencies in a specific directory, I think).

Also this should be possible with pipenv too. Both of those options allow you to ‘freeze’ an environment and make a requirements.txt file you can check in to a repo so users can pull down the right version of all your requirements fresh without your checking all your requirements into the repo, which is bloated and not a good idea.

I’ll follow up if I remember how I did that.

I love this technique for modules I use for every project. All of my servers get useful modules installed right in the TD path. It makes it so a lot of my reusable toxes function across projects.

Any time I have project independent modules I create a folder in my project folder called “external”. I add python modules in much the same way but targeting “external”.

Then in a startup script in TD I add:

import sys sys.path.append(project.folder+'/external') import <ExternalModuleHere>

You can then import the module where ever you need in the network.

I’ve never used virtualenv or pipeenv but I would be interested to see how you do that.

3 Likes