088: Adding Python Libraries

How does one add python libraries to 088? I am trying to add access to couchDBkit. Does anyone have a step-by-step walkthrough of the process?

Thanks.

Well, I didn’t personally investigate into it yet, but it seems there is an example project here:
viewtopic.php?f=22&t=3780

Thanks, I had looked at that one but didn’t understand it at first.
I was able to get some other libraries loaded by changing permissions on the Derivative folder to allow me to write to it. You can then download your package, Shift+RMB on the folder setup.py lives in and choose “Open Command Window Here”. Then use the following at the command prompt to install:

"C:\Program Files\Derivative\TouchDesigner088 64-Bit\bin\python.exe" setup.py install

This will install the package in the TouchDesigner\bin\Lib\site-packages folder so it can be found when you import. Hopefully that’s helpful to people.

I still have problems with couchdbkit. Maybe because it is not really ready for Python3? I get this with just import couchdbkit and Run Script in a textDAT. Ideas anyone?

Traceback (most recent call last):
  File "/project1/text1", line 1, in <module>
  File "C:\Program Files\Derivative\TouchDesigner088 64-Bit\bin\lib\site-packages\couchdbkit-0.6.3-py3.2.egg\couchdbkit\__init__.py", line 8, in <module>
    from .resource import  RequestFailed, CouchdbResource
  File "C:\Program Files\Derivative\TouchDesigner088 64-Bit\bin\lib\site-packages\couchdbkit-0.6.3-py3.2.egg\couchdbkit\resource.py", line 113
    except ResourceError, e:
                        ^
SyntaxError: invalid syntax

At first glance, looks like the module you’re trying to link with Python is failing under the new 3.x syntax.
From the website:
couchdbkit.org/download.html
It mentions “python 3.x will be supported soon”

That being said, modifying the TouchDesigner installation folder directly often causes problems in Windows installers trying to repair themselves etc.

A better approach, would be to:

  1. install the module to your local harddrive somewhere.
    Often its easiest to just install python3.2 on your system outside of TouchDesigner, and then install the packages you want to that installation.
  2. Append the locations of the new modules to your search path inside a specific TouchDesigner project when it starts up.

This is done with regular list manipulation:

 import sys
 sys.path.append(mymodulepath)

You shouldn’t keep appending to the list though.

So either:

  1. Just append once, using ‘On Start’ in an Execute DAT.

or

  1. check if its already in the list before importing your module:
 if mymodulepath not in sys.path:
     sys.path.append(mymodulepath)
 import mymodule

or

  1. use try/except:

try:

 import mymodule
 except ImportError:
     sys.path.append(mymodulepath)
     import  mymodule

Let us know if you require more details.

Cheers,
Rob

1 Like

Thanks for all of the info Rob,
I reinstalled TouchDesigner and Python to get all the default permissions back. I seem to be able to install some things correctly but I guess some of the modules just aren’t ready for python 3 so they fail when installing.
It seems like TD is happy finding the modules I’ve installed without appending the locations but I haven’t done extensive testing yet. The textport is at least not yelling at me when I import them.

Since couchDBkit and pyCurl won’t work is there and equivalent to the T-Script “system” command so I can send curl to couchDB directly from my Python script without having to send it to another textDAT and then using another DATexecute to run the script as T-Script?

Look into the subprocess module, its how you run external processes in python.

Python import may be a bit tedious: 3 hours that I try to get pywin32 working with Touch Designer with no luck.

If anyone got success to make pywin32 working with TD or to correclty install it, it’ll be kind to point me the right way of doing this.

Here what i’ve gone into so far:

  1. Installation of Python 3.2 - 64 bits at C:\Python32

  2. Installation of the pywin32-217.win-amd64-py3.2.exe binary for python 3.2.

  3. Command Prompt at C:\Python32\Scripts and

pywin32_postinstall.py -install

libpath = 'C:\\Python32\\lib\\site-packages' if libpath not in sys.path: sys.path.append(libpath) import win32com.client

Which rises an Attribute Error. Anyway, it may be a pywin32 related issue rather than a TD issue.

Edit: though, and even if that doesn’t solve the above error, one issue is that one needs to import each folder separately for modules to be imported

libpath = 'C:\\Python32\\lib\\site-packages'
lib1 = 'C:\\Python32\\lib\\site-packages\\win32\\test'
lib2 = 'C:\\Python32\\lib\\site-packages\\win32\\lib'


if libpath not in sys.path:
     sys.path.append(libpath)
     sys.path.append(lib1)
     sys.path.append(lib2)
import  win32com.client

Hi ab30.

One small thing Ive discovered, if you want to have the modules automatically visible to all TouchDesigner files, simply append their paths (separated by semicolons) to a system environment variable called PYTHONPATH.

In your case:

PYTHONPATH=
“C:/Python32/lib/site-packages;C:/Python32/lib/site-packages/win32/test’;C:/Python32/lib/site-packages/win32/lib”

(Forward slashes work in my examples, though I haven’t tested backslashes as you’re using).

I’ve listed all this info here for future reference:
derivative.ca/wiki088/index. … ng_Modules

Good luck with your pywin32 issue. Let us know if you’ve solved it.

Cheers,
Rob

1 Like

Hi Rob,

Thanks for the tip about PYTHONPATH.

I’ve not continued to try to implement pywin32, as it seems their installer is a bit inconsistent.

I wanted to use this library mainly for coding into VBscript directly inside Touch Designer, but for the moment, I’m going to wait for a more stable installation package, if it is updated one day.

Edit: That said, i installed the 32 bits version of pywin32 and it seems to work with python, but not with Touch Designer.

The following code works into the python console but rises a DLL import error with Touch Designer 32 bits:

Python Console:

import  win32com.client
sc = win32com.client.Dispatch("ScriptControl")
sc.language = "vbscript"
sc.addcode("""msgBox ("Hello World!")""")

TD:

PYTHONPATH="C:/Python32/lib/site-packages;C:/Python32/lib/site-packages/win32/test';C:/Python32/lib/site-packages/win32/lib"
import  win32com.client
sc = win32com.client.Dispatch("ScriptControl")
sc.language = "vbscript"
sc.addcode("""msgBox ("Hello World!")""")