1

In installed standalone jython on my ubuntu 12.04, run it, but if I try to import gtk, I get no module named gtk when in python console it works.

Update:

I have done

>> sys.path.insert(1,"/usr/lib/python2.7/dist-packages/gtk-2.0")

and

>> sys.path.insert(1,'/usr/lib/python2.7/dist-packages")

and now is is

    from glib._glib import *
ImportError: No module named _glib

when:

argon@vprime:/usr/lib/python2.7$ find | grep _glib
./dist-packages/gi/_glib
./dist-packages/gi/_glib/option.pyc
./dist-packages/gi/_glib/option.py
./dist-packages/gi/_glib/_glib.so
./dist-packages/gi/_glib/__init__.pyc
./dist-packages/gi/_glib/__init__.py
./dist-packages/glib/_glib.so
./dist-packages/twisted/internet/test/test_glibbase.pyc
./dist-packages/twisted/internet/test/test_glibbase.py
./dist-packages/twisted/internet/_glibbase.py
./dist-packages/twisted/internet/_glibbase.pyc
./dist-packages/_dbus_glib_bindings.so

so, glib/_glib is under dist-packages and I have no idea what is wrong...

1 Answer 1

1

Not all modules are compatible between Jython and CPython (the standard Python interpreter). In particular, modules that are compiled to native bytecode, generally written in C/++ (or with Cython), cannot be loaded in Java, because it uses its own Virtual Machine (JVM) which cannot understand native bytecode.

Many native/binary modules in CPython will have a name prefixed with an underscore, like _glib above.

You have at least two options:

  • Use Jython and a Java GTK package.
  • Use CPython, and if you need to talk to Java, use one of the packages that interface between CPython and the JVM (e.g. jpype, py4j).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.