pyx-project / pyx

Repository of PyX, a Python package for the creation of PostScript, PDF, and SVG files.
https://pyx-project.org/
GNU General Public License v2.0
109 stars 18 forks source link

OSError: Could not locate the file 'cmr10'. #7

Closed riku closed 5 years ago

riku commented 5 years ago

When I use

text.set(text.UnicodeEngine)

got error

Traceback (most recent call last):
  File "d:/MyFiles/LearnPython/pyx-unicode.py", line 3, in <module>
    text.set(text.UnicodeEngine)
  File "C:\Python36-32bit\lib\site-packages\pyx\text.py", line 1814, in set
    defaulttextengine = engine(*args, **kwargs)
  File "C:\Python36-32bit\lib\site-packages\pyx\text.py", line 1708, in __init__
    with config.open(fontname, [config.format.type1]) as f:
    raise IOError("Could not locate the file '%s'." % filename)
OSError: Could not locate the file 'cmr10'.

How to fix it?

wobsta commented 5 years ago

You need to take care of having the Type 1 fonts and PyX knowing where to find it. You can, for example, do the following (the instructions are for unix-like systems; it can be done similarly on Windows as well, but the position of the pyxrc is different and you need to generate an ls-R file somehow, depending on what you have available on your system):

  1. Download the amsfonts from http://www.ams.org/publications/authors/tex/amsfonts and extract it somewhere on your file system.

  2. In the directory where you just extracted the amsfonts, run ls -R > ls-R to create a file index.

  3. Create a .pyxrc in your home directory with the following content:

    [filelocator]
    methods = local internal ls-R
    ls-R = /<the full path of the diretory you extracted the amsfonts zip file>/ls-R

That's it, it will work now.

wobsta commented 5 years ago

Note that you can skip step 2 if you use the recursivedir locator and use the item name recursivedir to list the path to be searched for pfb and afm files. However, this results in the directory tree being crawled (and cached) each time. You could list several subdirctories and thus deeper into the directory structure to prevent PyX from reading directories, where nothing will be found anyway ...

djnugent commented 4 years ago

Script that does it for you. Note: this will blow out any existing .pyxrc file

mkdir ~/amsfonts
cd ~/amsfonts
wget http://mirrors.ctan.org/install/fonts/amsfonts.tds.zip
unzip amsfonts.tds.zip
ls -R > ls-R
echo "[filelocator]" > ~/.pyxrc
echo "methods = local internal ls-R" >> ~/.pyxrc
echo "ls-R = ${HOME}/amsfonts/ls-R" >> ~/.pyxrc