How to access external libraries in TD?

Hi,
I have to access scipy library in TD but when I tried to access it its saying a newer version of numpy is required. I have read some of previous TD forum posts and tried the tricks of removing TD path and appending custom path but its not working.
Python version im using in 3.7.2.
Any suggestions?

Printed sys.path and the numpy version

[‘C:/Users/DELL/AppData/Local/Programs/Python/Python37/Lib/site-packages’, ‘C:\Program Files\Derivative\TouchDesigner\bin’, ‘C:\Program Files\Derivative\TouchDesigner\bin\python37.zip’, ‘C:\Program Files\Derivative\TouchDesigner\bin\DLLs’, ‘C:\Program Files\Derivative\TouchDesigner\bin\lib’, ‘C:\Program Files\Derivative\TouchDesigner\bin’, ‘C:/Program Files/Derivative/TouchDesigner/Config/Cmd’, ‘C:/Users/DELL/AppData/Local/Programs/Python/Python37/Lib/site-packages’]
python >>>
1.16.2

Arun

I’ve found that it’s much easier to simply pip install versions of libraries that are compatible with the versions of the built in libraries, like numpy.

Most of the time we don’t need the latest and greatest version of libraries, and pip install will by default install the latest.

So the trick to resolve this is to go into the version notes for previous scipy releases and see what the numpy version requirements are, and go back until the td provided numpy satisfies that.


To find out what version of numpy we have, restart touch and run this:

import numpy
print( numpy.__version__ )
Result: 1.16.2

Then to dig backwards through scipy releases, you can search through their releases page (in scipy’s case). I like to page search, so something like this can work: "numpy 1. ". This takes us all the way back to 1.5.0 before the numpy requirement drops below 1.16.2.


Then, just scroll up until just before the version that bumps numpy up, which happens to be 1.5.4.

To summize, if you are working with the latest stable (2020.28110) pip uninstall the version of scipy you have, and pip install version 1.5.4 and I think you should be good.

The syntax for pip installing a specific version looks like this:

pip install scipy==1.5.4

I used to inject the python path at the very beginning of python’s sys.paths list, and that makes some sense because you’re trying to force a certain version of numpy or whatever, but I have had a lot of problems with that route.

Since we’re installing libraries that are compatible with the pre installed python, just append your new path to the end, and python will try to use the built in libs before the custom installed ones, which I think is ideal.


Incase it helps, here’s some other common python libs I install that are not default to Touch, who’s versions are fully compatible with the latest stable I mentioned above:
image

sklearn is the other big heavy hitter I’ve run into lots of problems with, but these versions are all good with numpy 1.16.2 I’ve found.

Hope this helps!

3 Likes

Thanks a lot !!! lucasm

1 Like