[bug #31091] python plugin: import gtk throws error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

URL:
  <http://savannah.nongnu.org/bugs/?31091>

                 Summary: python plugin: import gtk throws error
                 Project: WeeChat
            Submitted by: None
            Submitted on: Mon 20 Sep 2010 09:44:32 PM UTC
                Category: script API plugins
                Severity: 3 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: Leon Bogaert
        Originator Email: [hidden email]
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 0.3.3
                IRC nick: LBo

    _______________________________________________________

Details:

When I use "import gtk" or a library that uses gtk in a python plugin,
weechat throws an error:

python: stdout/stderr: Traceback (most recent call last):
python: stdout/stderr:   File "/home/leon/.weechat/python/windicate.py", line
24, in <module>
python: stdout/stderr:     import gtk
python: stdout/stderr:   File
"/usr/lib/pymodules/python2.6/gtk-2.0/gtk/__init__.py", line 42, in <module>
python: stdout/stderr:     import gdk
python: stdout/stderr: ImportError: No module named gdk
python: unable to parse file "/home/leon/.weechat/python/windicate.py"

When I use import gtk in a standalone script or in ipython it doesn't throw
an error.




    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

Update of bug #31091 (project weechat):

              Item Group:                    None => other                  
                  Status:                    None => Invalid                
             Assigned to:                    None => flashcode              

    _______________________________________________________

Follow-up Comment #1:

I think it's not a WeeChat bug. WeeChat just displays error from python, so
if you have this error, it's a python problem on your box.
Try to run python (to have interactive python shell), and do that:
import python

You should have same errors as WeeChat.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

Follow-up Comment #2, bug #31091 (project weechat):

I think you didn't read my comment:

When I use import gtk in a standalone script or in ipython it doesn't throw
an error.

So I made a testscript with the gtk import, ran it as python testscript.py =>
no error

Started the python shell: ipython
import gtk<CR>: no error

A very simple script in Weechat (with the import and a weechat.register):
error

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

Follow-up Comment #3, bug #31091 (project weechat):

I read your comment.
But I still think it's not a WeeChat bug, the error displayed is from python,
not from WeeChat.
I made a test script with "import gtk", like you, and I have no error
displayed in WeeChat.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

Follow-up Comment #4, bug #31091 (project weechat):

OK, sorry. Then I'll try another distribution first. What distribution are
you using?

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2

Follow-up Comment #5, bug #31091 (project weechat):

I'm using Debian.

(for more discussion about bugs, please join #weechat on irc.freenode.net,
it's faster than replying in bug)

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2
Follow-up Comment #6, bug #31091 (project weechat):

I realize this bug has been sitting around for three years...but I'm pretty
sure this is a bug in weechat.  It seems quite reproducible.  First, we start
with python on the command line, just to demonstrate that things are working
in general:


Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pynotify
>>>


Now, we load the lnotify.py script in weechat, and it works just fine:


/script install lnotify.py
python: loading script "/home/username/.weechat/python/lnotify.py"
python: registered script "lnotify", version 0.1.3 (lnotify - A
libnotify script for weechat)


We remove the script:


/script remove lnotify.py
python: unloading script "lnotify"
python: script removed:
/home/username/.weechat/python/autoload/lnotify.py
python: script removed: /home/username/.weechat/python/lnotify.py


And now try to load it again:


python: loading script "/home/username/.weechat/python/lnotify.py"
python: stdout/stderr: Traceback (most recent call last):
python: stdout/stderr:   File
"/home/username/.weechat/python/lnotify.py", line 20, in <module>
python: stdout/stderr:     import weechat, string, pynotify
python: stdout/stderr:   File
"/usr/lib64/python2.7/site-packages/gtk-2.0/pynotify/__init__.py",
line 19, in <module>
python: stdout/stderr:     import gtk
python: stdout/stderr:   File
"/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 42,
in <module>
python: stdout/stderr:     import gdk
python: stdout/stderr: ImportError: No module named gdk
python: unable to parse file
"/home/username/.weechat/python/lnotify.py"


KABOOM!

This happens every time.  Fedora 19, python 2.7.5, weechat 0.4.3.

Now, the problematic "gdk" module is loaded through some sort of weird magic,
so maybe weechat is doing something w/r/t dynamic library symbol lookups that
is making this fragile?



    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2
Update of bug #31091 (project weechat):

                  Status:                 Invalid => Need Info              
             Open/Closed:                  Closed => Open                  

    _______________________________________________________

Follow-up Comment #7:

The bug was not waiting, it was closed. So I reopen it.

I just tried to install lnotify.py, remove it, and reinstall it again, I have
no such error with gdk.
I'm using Debian Sid, Python 2.7.6, WeeChat 0.4.4-dev (same result with
0.4.3).
I tried on 2 machines: one with X, the other without X.
In both cases, I never see the error you have, so I'm not able to reproduce
the problem.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message posté via/par Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/weechat-dev
Reply | Threaded
Open this post in threaded view
|

[bug #31091] python plugin: import gtk throws error

Andreas Weber-2
Follow-up Comment #8, bug #31091 (project weechat):

I can reproduce the this problem on my Fedora 21 based system, using
 * WeeChat 1.0.1, ncurses client
 * PyGTK version 2.24.0
 * Python 2.7.8
 * "anotify.py" script, version 1.0.1
when reloading "anotify" (as described in comment #6).

@Sebastién: Which version of lnotify have you been using?  It seems that
lnotify has changed and does not use pynotify anymore, at least not since
version 0.2.0.

This problem is related to the use of Python sub-interpreters, which seem to
have trouble with native modules like gtk._gtk that modify the module
directory as part of their initialization code:
[https://docs.python.org/2/c-api/init.html#bugs-and-caveats]

It seems like dynamic objects (_gtk.so) are loaded only once per _process_,
which is why the initialization code is not re-run the second time the import
is triggered (by importing pynotify, which imports gtk, which imports _gtk),
and thus the module directory of the new interpreter state is not populated
with the "gdk" module.  Comment #6 was on the right track suspecting the
"weird magic" that is involved in loading "gdk", and that there is at least
_something_ on the WeeChat side (using sub-interpreters within a single
process) that triggers this bug (gtk being unable to find the "virtual" gdk
module).

This bug will also be triggered if two more more different Python scripts are
are importing the "gtk" module -- only the first one will succeed.

However, if anything, it can be considered a bug in Python, or in the
implementation details of PyGTK (not allowing for proper reloading), but it is
definitely not a bug in WeeChat.  I am not sure if there is a workaround that
does not involve chancing either Python or PyGTK.

    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?31091>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.nongnu.org/


_______________________________________________
Weechat-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/weechat-dev