Re: how to set PYTHONPATH to allow overrides in extra directories?



I dug a bit deeper.  It seems that pygobject actually wants the overrides directory to come later in sys.path, after /usr/lib/python3/dist-packages which holds pygobject itself (in the "gi" subdirectory).  And when I put the overrides directory in PYTHONPATH, it appears at the beginning of sys.path.

So now to put the overrides directory at the end, I've set PYTHONSTARTUP=~/.pythonrc, and in .pythonrc I've put this:

import sys
sys.path.append('/home/adam/local/lib64/python3/dist-packages')

And now the error I reported below ("cannot import name PyGIDeprecationWarning") no longer occurs.

That's the good news.  The bad news is that when I run gedit and try to run a plugin which uses an override provided in Gedit.py, it's still not found:

  File "/home/adam/local/lib64/gedit/plugins/quickopen/__init__.py", line 179, in on_quick_open_activate
    self._create_popup()
  File "/home/adam/local/lib64/gedit/plugins/quickopen/__init__.py", line 96, in _create_popup
    msg = bus.send_sync('/plugins/filebrowser', 'get_root')
AttributeError: 'MessageBus' object has no attribute 'send_sync'

So it seems that the override code is never being loaded.  (To confirm this, I put a print statement in Gedit.py, and it doesn't print.)  Does anyone have any idea why?

adam

On Sat, May 25, 2013 at 2:50 PM, Adam Dingle <adam medovina org> wrote:
Or, here's a simpler test case without reference to gedit.  (I have pygobject 3.9.1, by the way.)

1. Create files ~/test/gi/__init__.py and ~/test/gi/overrides/__init__.py, each containing

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

2. Run these commands:

$ export PYTHONPATH=~/test
$ python3
Python 3.3.2 (default, May 21 2013, 21:07:13) 
[GCC 4.8.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import foo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/gi/repository/__init__.py", line 25, in <module>
    from ..importer import DynamicImporter
  File "/usr/lib/python3/dist-packages/gi/importer.py", line 28, in <module>
    from .module import DynamicModule
  File "/usr/lib/python3/dist-packages/gi/module.py", line 37, in <module>
    from .overrides import registry
  File "/usr/lib/python3/dist-packages/gi/overrides/__init__.py", line 5, in <module>
    from gi import PyGIDeprecationWarning
ImportError: cannot import name PyGIDeprecationWarning

adam

On Sat, May 25, 2013 at 2:10 PM, Adam Dingle <adam medovina org> wrote:
gedit installs a file Gedit.py whch contains overrides for GObject introspection.  I've built and installed gedit locally (in /home/adam/local), and I have Gedit.py at

  /home/adam/local/lib64/python3/dist-packages/gi/overrrides/Gedit.py

I'm trying to get Python to recognize this overrides file.  According to this bug which was closed last August, it should be possible:


Following the instructions at https://bugzilla.gnome.org/show_bug.cgi?id=680913#c24, I've done the following:

- My PYTHONPATH is /home/adam/local/lib64/python3/dist-packages .
- I've created these files:

  /home/adam/local/lib64/python3/dist-packages/gi/__init__.py
  /home/adam/local/lib64/python3/dist-packages/gi/overrrides/__init__.py

Both of these files contain this text exactly:

  from pkgutil import extend_path
  __path__ = extend_path(__path__, __name__)

But now when I run gedit and try to enable a plugin which uses Python I see this:

Traceback (most recent call last):
  File "/home/adam/local/lib64/gedit/plugins/quickopen/__init__.py", line 20, in <module>
    from .popup import Popup
  File "/home/adam/local/lib64/gedit/plugins/quickopen/popup.py", line 23, in <module>
    from gi.repository import Gio, GObject, Pango, Gtk, Gdk, Gedit
  File "/usr/lib/python3/dist-packages/gi/repository/__init__.py", line 25, in <module>
    from ..importer import DynamicImporter
  File "/usr/lib/python3/dist-packages/gi/importer.py", line 28, in <module>
    from .module import DynamicModule
  File "/usr/lib/python3/dist-packages/gi/module.py", line 37, in <module>
    from .overrides import registry
  File "/usr/lib/python3/dist-packages/gi/overrides/__init__.py", line 5, in <module>
    from gi import PyGIDeprecationWarning
ImportError: cannot import name PyGIDeprecationWarning

This error does not occur when PYTHONPATH is not set.

What am I doing wrong?  Any clue?

adam


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]