Package managment helper Python

I’ve done a few interesting python gymnastics to make it easier to work with external libraries, especially for non python experts. The particular idea I’m currently chasing is using the python version distributed with TD to determine which version of a library to install in a directory that’s at a known location from the project file.

The idea here is that you then essentially end up with set of dependencies that can travel with your project rather than making changes to the TD install, or maintaining your own python installation that matches TD’s.

What I’ve been playing with is using a suprocess call to specify which python to use, and where to install the requested package.

Big gotchas so far are that TD is missing some essential pieces to make this easier:

  • pip
  • setuptools
  • pkg-resources

There are a few pieces above that I think I can work out, but it will for sure break when I install a new version of TD.

To that end, something that would be beyond helpful here would be a helper in the project class. That might look like:

def importExternalLibrary(library_string_name, destination_folder):
    # does a pip install of the requested library
    # in the specified directory
    # adds specified directory to project Paths

def importExternalReqs(path_to_requirements_txt, destination_folder):
    # does a requirements install with the path to the requirements txt
    # in the specified directory
    # adds specified directory to project Paths

I know this one isn’t as exciting as some of the other REF’s, but boy golly would it be helpful :slight_smile:

6 Likes

+1 20char20char20char20char20char

1 Like

Totaly in, but for now, did you take a look into my PIP Component? For one it enables PIP-Control (install, uninstall) but second it also holds the PIP library in the component and installs it into the local python library. I think it should be rather easy to extend to instead export in a project folder and add the path to the project folder to the search path.

td_pip.tox (1.4 MB)

Thanks @alphamoonbase - I’ll give this a look. My first attempt gives me a warning that I need to restart TD and run as admin, which is another barrier that I’ve been trying to avoid.

I’m curious if Derivative has some plans here - these kinds of handles would really be a great help IMO.

+1

pip install twentycharacters
import twentycharacters as thread_bump

1 Like

+1
Bad at python but would like to be able to use more python

+1 from me as well. This would really help

Thats in fact based on the new installer. It will write protect the install folder for some reasson. The old installer does not give that error. But I will see if I can implement it in a way that it is project dependant. Should not be to hard (last famous words)

+1
also curious if there’s a public list / RFE list for libraries that TouchDesigner is shipping along with Python installed by default. I think it was great when requests started shipping by default in TouchDesigner (I’m pretty sure it doesn’t ship with default Python? I could be wrong though, I don’t follow the Python news as much these days). Numpy was also a good add. I could imagine a few other libraries that might be worth considering default addition like pillow or similar.

1 Like

+1, would love to have something like this built in. Super useful!

+1 :slight_smile:

I’ve done some hackity hacks to get pip packages into Touch but I don’t feel great about commiting the source for a given version of package inside my project repo, or using a combination .gitignore and shell scripts to install the packages as needed.

I took your work into consideration and reworked everything a little bit.
The component now creates a LIB Folder in the Project folder and installs PIP and everything coming from PIP directly into that folder (and adds it to the import path for python.) So no more problems with Admin rights.
td_pip.tox (1.4 MB)

Very nice @alphamoonbase! This works great - I still want this in TD itself, but this is a nice work around.