Install FontForge Python bindings

Hello Community,

I’m working on a project that requires the FontForge Python bindings, but I’m having trouble installing them on Replit. The standard methods don’t seem to work in this environment. Has anyone successfully installed FontForge or its Python bindings on Replit? Any guidance, tips, or alternative solutions would be greatly appreciated!

Thank you in advance!

I don’t know much about FontForge.
But if you want to install certain dependencies, use the System Dependencies tool (replit uses nix).
For certain python packages, it is recommended to use the Packages tool (or let replit auto-install it) as this will also auto install any needed system dependencies for the package.

Hi @NuclearPasta0 thanks for the first response. In the list of the “Packages tool” there is not FontForge listed.

In other environments, I use CLI to install FontForge with Brew: brew install fontforge.

What will be the solution here?

To clarify, FontForge is not specifically a python package, it is a system dependency, which means it needs to be installed using nix (nix is what replit uses to manage dependencies for users).
So, open the System Dependencies tool. If there is no search bar, then click three dots and Show hidden files, and in .replit file, change channel under [nix] to "stable-23_05" or "unstable". Then, search for FontForge and install it with the tool.

See: https://search.nixos.org/packages?channel=23.05&from=0&size=50&sort=relevance&type=packages&query=FontForge
for the list of FontForge packages on nix. I’m not entirely sure which one is best to use. Note that if you install one that says it is a python package, there might be some (fixable) ModuleNotFoundErrors.

@NuclearPasta0 thank you for the clarification.
I’ve tried to change channel to both "stable-23_05" and "unstable". However, none of them causes the search bar to be displayed.

I’ve installed the FontForge by creating ‘replit.nix’ file.

{ pkgs }: {
  deps = [
    pkgs.python311Packages.fontforge.out #this is the FontForge version with Python packages
  ];
}

However, I am still getting en error:

ModuleNotFoundError: No module named 'fontforge'

It seems that the FontForge Python bindings aren’t recognized in the Replit’s environment, even though FontForge itself is installed.

First, you are using the python311Packages (as opposed to python310Packages). Is this the correct python version to be using? (I don’t know if there’s much of a difference though.)

So now, as with any “ModuleNotFoundError”, you should check PYTHONPATH (or equivalently, sys.path).
Note that with nix system dependencies, they are not installed in your repl locally (and so take up no user storage). (Python packages are installed in .pythonlibs.)
Nowhere in PYTHONPATH is pointing towards a fontforge module.

Current replit.nix (I didn’t include the .out suffix, not sure the effect):

{ pkgs }: {
  deps = [
    pkgs.python311Packages.fontforge
  ];
}

However, some investigation and we’ll find that fontforge does have some python modules, they just aren’t in PYTHONPATH.

/nix/store/q15npfvds00pfsxbbcq4s4rqgpxz8f83-fontforge-20230101/lib/python3.11/site-packages

So, we will configure the repl to include this path automatically.
replit.nix:

{ pkgs }: {
  deps = [
    pkgs.python311Packages.fontforge
  ];
  env = {
    FONTFORGEPATH = "${pkgs.python311Packages.fontforge}/lib/python3.11/site-packages";
  };
}

At the end of .replit:

[env]
PYTHONPATH = "$FONTFORGEPATH:$PYTHONPATH"

And reload. With this configuration, I was able to import fontforge.
Check PYTHONPATH again to make sure that the path to your local .pythonlibs site packages is still present (sometimes it can get overwritten).

This was helpful. Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.