How to install a package inside Glyphs App Python

I have a script to grab a daily featured wikipedia article as text.

But the version of the package it depends on to parse the feed (feedparser) no longer works in G3.

When I installed the latest version of it and simply dragged it into the Glyphs App /Scripts, there’s missing dependencies. If I try to import the same package in my shell python environment, it works. How do I install it correctly?

The easiest solution is probably to install a custom python version (brew or from python.org). Then you can use its pip to install whatever you need.
The Glyphs python might contain pip, too (I never checked). If you call it directly and figure out a way to give it a path outside of the Glyphs Python module …

I see… when I try to use a custom Python version, I get that error that says every single one of my plugins crashed. I’ll try again in debug mode and see how things work

You probably need to install pyobjc.

Bumping this

I’ve tried directly installing feedparser via pip inside the glyphs python, got this instead

Traceback (most recent call last):
  File "Get Random Featured Article of the Day.py", line 14
    html = d['entries'][randint(0,len(d['entries'])-1)]['summary_detail']['value']
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "random.py", line 362, in randint
    return self.randrange(a, b+1)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "random.py", line 345, in randrange
    raise ValueError("empty range for randrange() (%d, %d, %d)" % (istart, istop, width))
ValueError: empty range for randrange() (0, 0, 0)

I don’t think that is related to feedparser. It seems that d['entries'] is empty?

I have tried it and it works.

But every time I install a new Glyphs App version the internal python is re-written and all my installed packages are gone.

Is there any way to prevent this?

Best

Eigi

In the end I just copied the installed modules directly into my Glyphs App scripts folder manually.

~/Library/Application Support/Glyphs 3/Scripts is in sys.path inside Glyphs, you could use that as a target directory for pip, like this:

"Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/pip3" install --target "Library/Application Support/Glyphs 3/Scripts" --no-warn-script-location --upgrade ...

The installed modules should not be automatically overwritten there.

1 Like

This is it!

Thank you.

The only limitation is that installation in editable mode does not work. But I can live with it.