Thread overview
Need some help understanding PyD
Jan 09, 2017
Saurabh Das
Jan 09, 2017
Saurabh Das
Jan 11, 2017
xtreak
January 09, 2017
I've been giving PyD a try. It's really nice and mostly everything works out of the box.

I'm trying to use TensorFlow in D via Pytho, so I need to call Python functions in D.

When I try to do:

    auto context = new InterpContext();
    context.py_stmts("import tensorflow");

I get this error:

pyd.exception.PythonException@source/app.d(19):
ImportError: /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add
----------------
../../.dub/packages/pyd-0.9.8/pyd/infrastructure/pyd/exception.d:46 void pyd.exception.handle_exception(immutable(char)[], ulong) [0x5917f6]
../../.dub/packages/pyd-0.9.8/pyd/infrastructure/pyd/embedded.d:147 void pyd.embedded.InterpContext.py_stmts(immutable(char)[], immutable(char)[], ulong) [0x59149a]
source/app.d:13 _Dmain [0x573cb2]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x5abfae]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x5abf04]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x5abf6a]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x5abf04]
??:? _d_run_main [0x5abe61]
??:? main [0x575e6f]
??:? __libc_start_main [0x3fffbec4]
Program exited with code 1

How can I debug what the problem is?

Thanks,
Saurabh

January 09, 2017
PS: Noticed something off. My python installation is 3.4.3:
Python 3.4.3 (default, Sep 14 2016, 12:36:27)
[GCC 4.8.4] on linux

However when I run:
    context.py_stmts("import sys");
    context.py_stmts("print(sys.version)");

I get:
3.4.0 (default, Apr 11 2014, 13:08:40)
[GCC 4.8.2]


Also, when I import numpy from python3, it works, but if I do:
    context.py_stmts("import numpy");

I get this error:
pyd.exception.PythonException@source/app.d(20):
ImportError: /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add
----------------

January 11, 2017
On Monday, 9 January 2017 at 06:22:14 UTC, Saurabh Das wrote:
> PS: Noticed something off. My python installation is 3.4.3:
> Python 3.4.3 (default, Sep 14 2016, 12:36:27)
> [GCC 4.8.4] on linux
>
> However when I run:
>     context.py_stmts("import sys");
>     context.py_stmts("print(sys.version)");
>
> I get:
> 3.4.0 (default, Apr 11 2014, 13:08:40)
> [GCC 4.8.2]
>
>
> Also, when I import numpy from python3, it works, but if I do:
>     context.py_stmts("import numpy");
>
> I get this error:
> pyd.exception.PythonException@source/app.d(20):
> ImportError: /usr/lib/python3.4/lib-dynload/_ctypes.cpython-34m-x86_64-linux-gnu.so: undefined symbol: _PyTraceback_Add
> ----------------

I think you need to upgrade Python. I googled "_PyTraceback_Add" and got this http://stackoverflow.com/questions/33223713/python-ctypes-import-error-in-virtualenv . Also refer to this comment http://stackoverflow.com/questions/33223713/python-ctypes-import-error-in-virtualenv#comment54266298_33223713 . Hope this helps.