How to import a Python module with a dll (pyd) ?

Hi,

Wanted to have a play with physics sim in Touch through Python but I’m stuck quite early.
When I try to import a module which has a dll (a .pyd), I get

“Runtime error!
R6034 - An application has made an attempt to load the C runtime library incorrectly”

Anyway to make it work ?

I tried with pyODE and pyBox2D from lfd.uci.edu/~gohlke/pythonlibs/, works fine with my standalone python installation (c:\python32)

Found some pointers, here :
kb.froglogic.com/display/KB/Arti … on+modules

Before I spend more time with this it would be great to know if it can work!

Touch088 - 8380 x64

Thanks a lot
Cheers
Vincent

bump this.

I want to load pygame for the keyboard controls, and I get errors, though different:

File "<string>", line 1, in <module> File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 140, in tdcustomimport r = previousimport(*args, **kw) File "C:\Python32\Lib\site-packages\pygame\__init__.py", line 136, in <module> from pygame.base import * File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 140, in tdcustomimport r = previousimport(*args, **kw) ImportError: DLL load failed: The specified module could not be found.

I couldnt find a Python 3.2 installer for PyODE. However I tried loading Box2D and pygame and although I can load it into stand alone 3.2 - they fail in the same way for me inside TouchDesigner. I have submitted this as a high priority bug. Should be fixed in an upcoming release. Thanks for pointing this out.

Jarrett

Box2D is going to be AWEsome :smiley:

@ Jarrett : good to know, thanks for the update! The website I posted has 3.2 builds for lots of useful libraries, much more than on the official websites, including ODE (no pyBullet though, but I may have a go at compiling it at some point though it looked painful)

@ sunspider : I posted the error in the popup window, but I had the same as yours in the textport. Yeah, physics in Touch should be cool :slight_smile:

Hello physics addicts,
I also tried to run the lib and some examples and it seems it’s still not working.
I added the attached lib to the Derivative folder and tried running the hello example in a textDAT

[code]from Box2D import (b2PolygonShape, b2World)

world = b2World() # default gravity is (0,-10) and doSleep is True
groundBody = world.CreateStaticBody(position=(0, -10), shapes=b2PolygonShape(box=(50, 10)))

Create a dynamic body at (0, 4)

body = world.CreateDynamicBody(position=(0, 4))

And add a box fixture onto it (with a nonzero density, so it will move)

box = body.CreatePolygonFixture(box=(1, 1), density=1, friction=0.3)

Prepare for simulation. Typically we use a time step of 1/60 of a second

(60Hz) and 6 velocity/2 position iterations. This provides a high quality

simulation in most game scenarios.

timeStep = 1.0 / 60
vel_iters, pos_iters = 6, 2

This is our little game loop.

for i in range(60):
# Instruct the world to perform a single step of simulation. It is
# generally best to keep the time step and iterations fixed.
world.Step(timeStep, vel_iters, pos_iters)

# Clear applied body forces. We didn't apply any forces, but you should
# know about this function.
world.ClearForces()

# Now print the position and angle of the body.
print(body.position, body.angle)

[/code]

I managed to have it working in the python standalone shell as well
but I get this same error in TD

File "/project1/text1", line 4, in <module> File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\Box2D\__init__.py", line 20, in <module> from .Box2D import * File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\Box2D\Box2D.py", line 32, in <module> _Box2D = swig_import_helper() File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\Box2D\Box2D.py", line 28, in swig_import_helper _mod = imp.load_module('_Box2D', fp, pathname, description) File "C:\Program Files\Derivative\TouchDesigner088\bin\lib\imp.py", line 183, in load_module return load_dynamic(name, filename, file) ImportError: DLL load failed: %1 is not a valid Win32 application.

What’s missing that would make it work ?
I’m using vvvv at the moment for a personal project using simple 2D physics, I would love to port it to TD :slight_smile:

Thanks a lot !
Box2D.zip (426 KB)

Any chance the library is the 32-bit version?

You might want to try looking into Pymunk, I had v.4 working quite well with 64 bit.
V.5 is out now & haven’t tested, however samples were fairly easy to port over.

Calvin

Thanks @zcalvin, I tried again today with no luck with the pymunk5.2.0 latest version due to some DLL error I didn’t manage to fix

but it looks like it’s working in TD088 32bit with pymunk4.0.0

a box falling

python >>> Box created Vec2d(50.0, 100.0) Vec2d(50.0, 100.0) Vec2d(50.0, 99.6) Vec2d(50.0, 98.8) Vec2d(50.0, 97.6) Vec2d(50.0, 96.0) Vec2d(50.0, 94.0) Vec2d(50.0, 91.6) Vec2d(50.0, 88.8) Vec2d(50.0, 85.6) Vec2d(50.0, 82.0)

trying to run the examples at the moment

Hey there !

I have imported pymunk-4.0.0 on TD088 64 bits but keep having this error :

DAT compile error: /project1/chopexec1 Traceback (most recent call last): File "/project1/chopexec1", line 1, in <module> File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:/Users/rubym/AppData/Local/Programs/Python/Python36/Lib\pymunk\__init__.py", line 58, in <module> from . import _chipmunk_cffi File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:/Users/rubym/AppData/Local/Programs/Python/Python36/Lib\pymunk\_chipmunk_cffi.py", line 3, in <module> from pymunk._chipmunk_cffi_abi import ffi, lib, lib_path File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) File "C:/Users/rubym/AppData/Local/Programs/Python/Python36/Lib\pymunk\_chipmunk_cffi_abi.py", line 1463, in <module> ffi = FFI() File "C:/Users/rubym/AppData/Local/Programs/Python/Python36/Lib\cffi\api.py", line 56, in __init__ import _cffi_backend as backend File "C:/Program Files/Derivative/TouchDesigner088/bin/TouchInit.py", line 205, in tdcustomimport r = previousimport(*args, **kw) ImportError: No module named '_cffi_backend'

I have re-installed the cffi module can’t seem to make it work. Any hints on what’s the problem ?

I managed to get pybox2d to import into Touchdesigner 099 (14220) and drive a simple simulation (see attached .toe).

The key seems to be building pybox2d from the GitHub source code, and making sure it builds and installs specifically for Python 3.5 64-bit. Once I had pybox2d built and installed in my standalone Python 3.5 installation, I was able to copy the Box2D folder from the standalone Python 3.5 installation folder (Python35\Lib\site-packages) into the TouchDesigner099\bin\Lib\site-packages folder.

I’m curious what other people who have experience with Box2D in C++ think about the performance of pybox2d in Touchdesigner. With 500 bodies in the simulation I’m only getting about 45 fps on a 3.5 GHz i7.

When running the .toe, press “1” to reset the simulation
box2d_test.24.toe (24 KB)

Hey Beau,

Though I gave up on python for any kind of performance task a while ago, happy to see this 4 years old thread resurrected :wink:

First for lazy people like me the precompiled binaries Box2D‑2.3.2‑cp35‑cp35m‑win_amd64.whl from lfd.uci.edu/~gohlke/pythonlibs/#pybox2d actually work fine with TD.

Second it seems the bottleneck is filling the DAT table. Changing the end of code to

[code]
import time

t1=time.time()

b = 0
for body in world.bodies:
	if(b<100):
        opTable[b,0] = body.position[0]
        opTable[b,1] = body.position[1]
        opTable[b,2] = body.angle
        for fixture in body.fixtures:
            shape = fixture.shape
            opTable[b,3] = shape.radius #
        b += 1


t2=time.time()

print(1000*(t2-t1))[/code]

only updating the first 100 rows, it’s 5ms (time.time() is seconds), compared to 20ms for the whole table (60fps is 16ms per frame max).

Had a quick play with box2d c++ and was still getting 60fps for 1600 boxes.

I’ll let the python experts chime in as to what’s the best way to bring the data back in TD world, I wonder if filling a scriptCHOP would make any difference.

Curious what the performance is in the VVVV port and how it’s done, Philippe D that I see above in the thread might have some insight :wink: