0

I'm using rdkit.

After a build using py2exe, when I call the Draw.MolToImage method there is an error:

Warning: unable to load font metrics from dir 
C:\pythonApp\dist\library.zip\rd
kit\sping\PIL\pilfonts
Traceback (most recent call last):
    File "app.py", line 470, in <module>
    img=Draw.MolToImage(part[i])
    File "rdkit\Chem\Draw\__init__.pyc", line 124, in MolToImage
    File "rdkit\Chem\Draw\MolDrawing.pyc", line 536, in AddMol
    File "rdkit\Chem\Draw\MolDrawing.pyc", line 351, in _drawLabel
    File "rdkit\Chem\Draw\spingCanvas.pyc", line 74, in addCanvasText
    File "rdkit\sping\PIL\pidPIL.pyc", line 333, in drawString
ValueError: bad font: Font(12,0,0,0,'helvetica')`

There is no difference if I put these files into library.zip (to \rdkit\sping\PIL\pilfonts) or just into the dist folder and change paths in pidPIL.py to valid; the application still cannot open metrics.dat.

Without the py2exe conversion, everything works perfectly.

SwiftArchitect
  • 47,376
  • 28
  • 140
  • 179
mahoney
  • 11

1 Answers1

0

Are you using 'data_files' in your setup.py to include the pilfonts folder?

E.g. something along these lines:

setup(

    data_files = [("pilfonts", glob.glob("\rdkit\sping\PIL\pilfonts\*.*"),

    options = {"py2exe": {"compressed": 2,
    # etc etc
)
Werner
  • 2,086
  • 1
  • 15
  • 14
  • I've tried your way and also [this solution](http://crazedmonkey.com/blog/python/pkg_resources-with-py2exe.html) but without any results. – mahoney Sep 02 '15 at 17:54
  • What/where does pidPil.py expect the folder to be? Add a print/breakpoint to the figure this out. – Werner Sep 02 '15 at 21:25
  • Paths were correct, but app couldn't open the file. I "fixed" it in other way. Just changed rendering lib to `py2cairo`. No `PIL` files - no problem. – mahoney Sep 05 '15 at 16:49