pytroll / aggdraw

Python package wrapping AGG2 drawing functionality
https://aggdraw.readthedocs.io/en/latest/
Other
98 stars 48 forks source link

aggdraw does not some to be able to find fonts when installed in a venv #74

Open eteq opened 3 years ago

eteq commented 3 years ago

Minimal steps to reproduce (on Ubuntu 21.04, Python 3.9):

in terminal

% python -m venv aggdrawtest
% source  aggdrawtest/bin/activate
% pip install aggdraw
% python

in python:

>>> import aggdraw
>>> aggdraw.Font('black', '/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: cannot load font (no text renderer)

By contrast, if I do sudo apt install python3-aggdraw I see this in python:

>>> import aggdraw
>>> aggdraw.Font('black', '/usr/share/fonts/truetype/open-sans/OpenSans-Regular.ttf')
<Font object at 0x7f3847abcd10>

Clearly something is going wrong in the venv install. Any ideas?

eteq commented 3 years ago

(note I see the same error if I do python setup.py install in the same venv. Which really ought to be true but hey sanity checks are nice)

eteq commented 3 years ago

Aha! I figured out the problem, although I'm not sure what the best solution is here:

It turns out aggdraw was not finding freetype because pkgconfig was not installed. When I installed it, python setup.py install worked. However, even if I do pip install pkgconfig before the pip install aggdraw, it still doesn't work. My hunch is that something is wrong with the wheel? At any rate, I have a workaround that works for me locally at least.

I'll try to make a PR to at least catch this error, but the wheel probably needs fixing too?

djhoese commented 3 years ago

Normally pkgconfig is the last resort for finding freetype:

https://github.com/pytroll/aggdraw/blob/bd751fc2e27554c06736fa0e2db55a6eb2ee87ac/setup.py#L101-L110

Do you have the output from when you run pip install (or python setup.py install)? Some of the messages should show whats going on inside the setup.py.

We do not currently have wheels published for Python 3.9 (see #73) so no matter how you install it into a python 3.9 environment it will be building from source. The wheels (for non-3.9 versions) should have freetype expected/builtin.

I don't know anything about the debian packages. What version does it install? Is it built from source with freetype? Do they include any patches to this source to hardcode the location of the freetype library? There's a lot of stuff that could be going on to make this work better.

Do you get any result if you do which freetype-config? If so, what about freetype-config --prefix? I ask because:

https://github.com/pytroll/aggdraw/blob/bd751fc2e27554c06736fa0e2db55a6eb2ee87ac/setup.py#L62