How to import fontforge to python in windows 7
Asked Answered
C

1

6

Environment: Win 7, Python 3.4, Sublime Text 2

I am trying to use fontforge as in following example, by importing fontforge in *.py:

import fontforge
font = fontforge.open('blank.sfd')
...

However, I haven't found any help for win 7 on where (or which subset) to include fontforge binary in my project to make it work. Any ideas, please? Thanks

Edit: I was trying to build it with pyextension in win 7 as described here:

http://fontforge.org/source-build.html#MS

via cygwin it fails on executing ./configure --enable-pyextension

throwing
checking for gcc
result: no    
checking for cc
result: no
checking for cl.exe
result: no
error: in `/cygdrive/c/fontforge':
no acceptable C compiler found in $PATH

Edit 2: By installing C compiler I've managed to ./configure it but my attempts have failed on executing make install command. I got following error, preceding another countless lines:

Makefile:91: recipe for target '../libfontforge.la' failed
make[1]: *** [../libfontforge.la] Error 1
make[1]: Leaving directory '/cygdrive/c/fontforge/fontforge'
Makefile:28: recipe for target 'fontforge' failed
make: *** [fontforge] Error 2
Cribwork answered 29/4, 2014 at 12:56 Comment(8)
What is the error when you import fontforge. Did you build FF with the Python extension enabled?Presentative
@Presentative I was trying to build it with pyextension in win as described here: fontforge.org/source-build.html#MS via cygwin it fails on ./configure --enable-pyextension throwing checking for gcc result: no checking for cc result: no checking for cl.exe result: no error: in `/cygdrive/c/fontforge': no acceptable C compiler found in $PATHCribwork
You need to install a C compiler and try again.Presentative
Thanks, @allcaps, I've installed a C compiler, but I've failed on another command getting an error as described above. Do you have any idea, why it might be so?Cribwork
Nope, can't help you. Maybe the Fontforge mailing list?Presentative
Did you manage to do this eventually? And in that case, how? I'm having the same problem.Mohr
HI @Mohr I'm sorry I haven't managed to do it. Any progress at your side?Cribwork
@Cribwork I gave up as well. I'm now using FontTools, which had the functionality I needed. But it would be great if there was a way to access FontForge from python in windows... short of doing a windows build of course.Mohr
A
12

Install fontforge for windows, then search your install for a fontforge-console.bat, and double-click it. From there you have a python environment that includes fontforge via the command:

ffpython

e.g.:

ffpython yourPythonFontForgeScript.py

You may need to cd to whatever directory has your python script before running that command, or otherwise make sure that the script is in your %PATH%.

Anguilliform answered 4/3, 2017 at 6:28 Comment(4)
Thanks, got me where I needed to be. using windows and not cygwin, but mehImpossibly
This is probably a helpful answer for most folks just trying to get some Python scripting to work with FontForge on Windows (it definitely helped me), but it's worth noting that ffpython is FontForge's own copy of Python (not your system's Python), and if you simply downloaded the prebuilt Windows installer (as of this writing, FontForge-2017-07-31-Windows-r2.exe), then ffpython is Python 2, not Python 3. (Specifically, the 2017-07-31 build contains Python 2.7.13.)Scyros
Running ffpython somescript.py still produces an error if you add import fontforge at the top. ModuleNotFoundError: No module named 'fontforge' (At least for me)Astromancy
@Jay you run fontforge-console.bat. When that is done, in the same window, run ffpython, as if it were any other python interpreter.Phreno

© 2022 - 2024 — McMap. All rights reserved.