Better method for installing Python dependencies

I have been developing several Glyphs plugins that require external Python dependencies (examples include NumPy, Pillow, Mido). I understand from this topic that I can symlink or manually add the paths to the libraries. However, the above packages are not simply single folders that I can locate and copy. For example, Mido has other dependencies that I am not completely familiar with, so I wouldn’t know which libraries I would need; NumPy is compiled so it contains non-Python libraries which are scattered in different places.

I could install a custom version of Python, install pyobjc and these libraries and change the version in Preferences. However, I don’t think this is easy to follow for non-developers and any end-user.

All this is to say that I wish there could be a better way to install and manage packages for the Glyphs version of Python. The back-end of it should be relatively straightforward as Pip already does all the dependency management.

In the meantime, is there any way to install packages into Glyph’s version of Python?

You can install it into the ~/Library/Application Support/Glyphs 3/Scripts/site-packages.
you need to find a python 3.10, then you can run this:

/Library/Frameworks/Python.framework/Versions/3.10/bin/pip3  install --target="/Users/YOUR USER NAME/Library/Application Support/Glyphs 3/Scripts/site-packages" numpy

You need to replace “YOUR USER NAME” with the name of your user folder.

1 Like

Hi thanks! I was wondering if there is an easier method to install packages - say, if I want a non-developer user to use my plugin. Could there be a simple GUI for pip?

I’ll think about it.

1 Like

you need to find a python 3.10, then you can run this:

The default Python in 3.2(3205) is 3.9.1

Here’s a cut-and-pastable that seems to have worked for me

python3.9 -m pip install --target="/Users/$USER/Library/Application Support/Glyphs 3/Scripts/site-packages" numpy

It’s already 3.11. To upgrade your Python, just uninstall and reinstall the module.

Thanks for this. Just to clarify:

  • You would need an additional copy of Python in order for @SimonC 's method to work. This copy has to be in the same version as Glyphs’s Python.
  • Glyphs’s Python module does not come with its own pip, hence we need to use pip from another copy of Python.
  • Once you uninstall and reinstall the Python module in Glyphs, all previously installed pip libraries would be gone and would need to be reinstalled.

Are these correct?

The first two points are true. The third is not. The mentioned folder is outside the Glyphs python module.

1 Like