Unable to import 'noise' module - Script beginner

Hi,

I have been working on a script for a personal project and I have reached a point in which I would like to experiment with incorporating noise. I have been able to execute all of the previous versions of my script without issue importing the ‘random’, ‘math’, ‘json’ modules without issues.

I have looked at a few previous forum posts as to how to install the ‘noise’ module but I have not had success on my end following those discussions. I cannot seem to get past this error:

Traceback (most recent call last):
  File "<macro panel>", line 1
ModuleNotFoundError: No module named 'noise'

For context, my currently Glyphs 3 (3.3.1) is using the 3.11.9 (Glyphs) Python version on macOS 15.3.2. Perhaps unrelated but my system version of Python is 3.12.2, it was installed using Homebrew and for whatever reason I cannot seem to update any modules, let alone pip with receiving this error in my terminal:

error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
    xyz, where xyz is the package you are trying to
    install.
    
    If you wish to install a non-brew-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-brew packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

[notice] A new release of pip is available: 24.0 -> 25.0.1
[notice] To update, run: python3.12 -m pip install --upgrade pip

Thank you in advance for any help and I apologize if this is a simple fix!

I was able to make some progress by running this in my terminal:

pip3 install --target="/Users/$USER/Library/Application Support/Glyphs 3/Scripts/site-packages" noise

However now I am running into this error when attempting to import the module in the Macro Panel:

Traceback (most recent call last):
  File "<macro panel>", line 11
  File "__init__.py", line 12
    from . import _perlin, _simplex
ImportError: cannot import name '_perlin' from partially initialized module 'noise' (most likely due to a circular import) (/Users/$USER/Library/Application Support/Glyphs 3/Scripts/site-packages/noise/__init__.py)

Do you have the correct version of the noise package matching your Glyphs Python version in your site-packages folder? When you use pip3 in Terminal, it will use the pip command from your Homebrew Python, so you will get whatever pip installs for Python 3.12. A version mismatch may explain the error.

If you don’t have the same system Python and Glyphs Python version, installing packages is a pain in the ass. You could run pip from the Macro Panel. See here for code that you can adapt: fontc-export-plugin/fontcExport.glyphsFileFormat/Contents/Resources/plugin.py at main · googlefonts/fontc-export-plugin · GitHub

The Glyphs python contains a working pip, now:

/Users/$USER/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/pip3 install --target="/Users/$USER/Library/Application Support/Glyphs 3/Scripts/site-packages" noise
2 Likes

That worked exactly the way I needed.

Thank you for this!

If you need to run pip for Glyphs more often, you could also set an alias in your .zshrc:

alias pip-glyphs3='$HOME/Library/Application\ Support/Glyphs\ 3/Repositories/GlyphsPythonPlugin/Python.framework/Versions/3.11/bin/pip3 install --target="$HOME/Library/Application Support/Glyphs 3/Scripts/site-packages"'