Better method for installing Python dependencies

I fixed it.

I would recommend to install into the Scripts/site-packages

~/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3 install -t ~/Library/Application\ Support/Glyphs\ 3/Scripts/site-packages numpy

On Glyphs 3.2 with Python 3.11 I ran this:

~/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3 install -t ~/Library/Application\ Support/Glyphs\ 3/Scripts/site-packages numpy

also tried with the full path in quotes instead of with :

"/Users/MYUSERNAME/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3" install -t "/Users/MYUSERNAME/Library/Application Support/Glyphs 3/Scripts/site-packages" numpy

and get this error:

zsh: /Users/MYUSERNAME/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3: bad interpreter: ./python3.11: no such file or directory

Questions:

  1. Since there is no existing Scripts/site-packages folder, do I have to manually create one?
  2. In a comment above you mention replace ~ with the path of your user folder, do I have to do that in this case?

This is annoying. It seems works for me. Need to investigate.

If someone likes to try. The pip3 file is actually a python script that can be edited. I removed the absolute path to the python binary in the first line at tried to make it relative.

Somehow the “official” Python still seems to be referenced in there somewhere:

> cd "/Users/kuti/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin"
> ./python3.11
dyld[84062]: Library not loaded: /Library/Frameworks/Python.framework/Versions/3.11/Python
  Referenced from: <DAEA9A8A-1F43-3E78-A8D3-A4275D00B4E5> /Users/kuti/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11
  Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file), '/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file, not in dyld cache)
zsh: abort      ./python3.11

This may be depending on the shell you are using, but for zsh:

~ is expanded to your user folder, but only if the whole path is not typed with surrounding quotes. Without quotes, you have to escape the spaces though…

So ~/Library/Application\ Support works, but "~/Library/Application Support" doesn’t.

If you’re running the latest stable Glyphs 3.1.2, then Scripts/site-packages is not in the PYTHONPATH environment variable for GlyphsPython. Once you’ve installed your dependencies there, you need to start your scripts with this:

import sys
sys.path.append('/Users/[username]/Library/Application Support/Glyphs 3/Scripts/site-packages')

Then you can import your dependencies, and GlyphsPython will be able to find them now. I was able to import hyperglot and numpy for example.

Can you try the latest cutting version?

Has anyone arrived to get it working?

Following last Georg instructions, modules are correctly installed in Scripts/site-packages, but most of installed module return error when I tried to import them in Glyphs.

Hyperglot is the only one that works. :frowning:

Most of the error indicates that a module is compiled for the ‘x86_64’ architecture but my system requires the ‘arm64’ architecture, leading to an architecture incompatibility issue.

If we could have something similar to the “Install Python Packages…” feature from Drawbot, that would be fantastic :smiling_face_with_tear:

Can you check if you Terminal app is running in Intel or Arm mode? Activity Monitor app can tell you.

Intel
Using “Apple M1 Pro” chip

Then get to the Terminal app in Finder, hit Cmd+i. In the info box, there should be a checkbox “use Rosetta” (or similar). Uncheck it. Restart Terminal. The uninstall all modules and install them again.

1 Like

It worked, thank you @GeorgSeifert!

Most of module work, but I have a issue similar to @jkutilek.
With python-fontbro module I got :

Traceback (most recent call last):
  File "<macro panel>", line 1
  File "__init__.py", line 1
    from fontbro.font import Font
  File "font.py", line 6
    from curses import ascii
  File "__init__.py", line 13
    from _curses import *
ImportError: dlopen(/Users/hugojourdan/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_curses.cpython-311-darwin.so, 0x0002): Library not loaded: /Library/Frameworks/Python.framework/Versions/3.11/lib/libncursesw.5.dylib
  Referenced from: <4891AC09-81E7-34E9-A8E9-D072F4EE559A> /Users/hugojourdan/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_curses.cpython-311-darwin.so
  Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.11/lib/libncursesw.5.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OS/Library/Frameworks/Python.framework/Versions/3.11/lib/libncursesw.5.dylib' (no such file), '/Library/Frameworks/Python.framework/Versions/3.11/lib/libncursesw.5.dylib' (no such file), '/usr/lib/libncursesw.5.dylib' (no such file, not in dyld cache)

Has anyone made any progress on this? I would like to be able to use pip to install dependencies in GlyphsPython, without the user being required to install another Python.

@GeorgSeifert mentioned that pip was added to GlyphsPython last October, but it doesn’t work. Everything in the GlyphsPython bin folder points to /Library/Frameworks/Python.framework/… which is where Python.org installations live. Is there a working Python (or pip) executable anywhere inside of GlyphsPython that can be run from the command line? I can’t find one.

Another problem that may need to be solved before pip can be used in GlyphsPython is that setuptools is apparently missing. The pip module is there, but I get various errors indicating setuptools is missing if I try to run pip via runpy, and if I try to run ensurepip. Try running these in the Macro window:

import runpy
import sys
sys.argv = ['pip', 'install', '--upgrade', '--target', "~/Library/Application Support/Glyphs 3/Scripts/site-packages", 'hyperglot']
runpy.run_module("pip", run_name="__main__")
import ensurepip
ensurepip.bootstrap()

The ensurepip.bootstrap method complains that a specific wheel of setuptools is missing, but if I go dig up that exact file from pypi and run it again, Glyphs gets a permanent spinning wheel and stops responding.

This works for me.

That doesn’t work for me. Do you have 3.11 installed somewhere else? GlyphsPython’s pip command has its shebang pointing to ./python3.11, which is some kind of executable that runs Python by looking for it in Library/Frameworks and System/Library/Frameworks. I just get errors that it can’t find 3.11 in those locations.

Here are the errors:

When I run your command as-is…

~/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3 install -t ~/Library/Application\ Support/Glyphs\ 3/Scripts/site-packages numpy

…it doesn’t work because of the relative shebang in pip3.

zsh: /Users/justinpenner/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/Current/bin/pip3: bad interpreter: ./python3.11: no such file or directory

If I go to the GlyphsPython bin folder first before running your command, then I get this error…

dyld[75363]: Library not loaded: '/Library/Frameworks/Python.framework/Versions/3.11/Python'
  Referenced from: '/Users/justinpenner/Library/Application Support/Glyphs 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/python3.11'
  Reason: tried: '/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file), '/System/Library/Frameworks/Python.framework/Versions/3.11/Python' (no such file)
zsh: abort       install -t ~/Library/Application\ Support/Glyphs\ 3/Scripts/site-packages 

…because the relative shebang (bin/python3.11) is now found, but that executable can’t find any installations of Python 3.11.

ETA: It seems like the real Python executable is the file called Python with a capital P, up one level from the bin folder. bin/python3.xx appears to be a binary executable that is some sort of wrapper that should be looking for Python in ../ but instead is looking for it in the absolute path for a typical Python installation. This seems to be somewhat related to this issue and this issue.

This is odd as Georg’s command also works for me. Have you tried reinstalling the Python module in Glyphs? I have both the Python executable that you mentioned a level up and python3.11 in bin.

You are right. The pip in the plugin picks up the python from Library/Frameworks. I tried to relink it but didn’t manage to get it to work.

@georgeyjm you probably have Python 3.11 installed in /Library/Frameworks or /System/Library/Frameworks. Georg’s command shouldn’t work unless you have a Python distro installed in one of those locations.

@GeorgSeifert This is getting far out of my depth, but I suspect the solution would involve modifying some of bin/pip* and bin/python* binary files, either by editing directly or rebuilding from source. Those are the command line executables which wrap the ../Python interpreter library. It might be a lot of work to fix them, so I don’t know if it would be worth the effort.

For now, if anyone is building a GlyphsApp plugin that requires dependencies to be installed via pip, the user must install Python separately to get a working copy of pip. It does not need to be the same Python version as GlyphsPython (currently 3.11) as pip can be tricked into installing packages for other Python versions with the --python-version argument.

Here’s the command I’m currently using in the README.md of my plugin. This works with any Python selected in Glyphs > Preferences > Addons, but the user must replace the version number in this command with whatever Python version they are using in Glyphs.

pip3 install --python-version=3.11.6 --only-binary=:all: --target="/Users/$USER/Library/Application Support/Glyphs 3/Scripts/site-packages" --upgrade hyperglot urlreader pyobjc cocoa-vanilla
1 Like

I’ll try to get this to work properly. Until then your suggestion is helpful. Thanks.