Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when checking FreeType version #5444

Closed
hugovk opened this issue Apr 26, 2021 · 4 comments · Fixed by #5445
Closed

TypeError when checking FreeType version #5444

hugovk opened this issue Apr 26, 2021 · 4 comments · Fixed by #5445

Comments

@hugovk
Copy link
Member

hugovk commented Apr 26, 2021

After PR #5098:

$ python
Python 3.9.4 (default, Apr 20 2021, 15:51:38) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL.ImageFont
>>> PIL.ImageFont.FreeTypeFont()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.9/site-packages/PIL/ImageFont.py", line 173, in __init__
    freetype_version = parse_version(features.version_module("freetype2"))
  File "/usr/lib/python3.9/site-packages/packaging/version.py", line 57, in parse
    return Version(version)
  File "/usr/lib/python3.9/site-packages/packaging/version.py", line 296, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

The ImageFont module tries to be accepting of missing (optional) system dependencies for the _imagingft module. But then features.version_module() returns None, which cannot be parsed as a version, so this dumps a completely incomprehensible traceback rather than what most of the rest of this module does, which is:

class _imagingft_not_installed:
# module placeholder
def __getattr__(self, id):
raise ImportError("The _imagingft C module is not installed")
try:
from . import _imagingft as core
except ImportError:
core = _imagingft_not_installed()

Originally posted by @eli-schwartz in #5098 (comment)

@radarhere
Copy link
Member

I've created PR #5445 to resolve this.

@mohammed70777

This comment has been minimized.

@EllieTheYeen
Copy link

I had this problem a few days ago and first suspected packaging to be behind it which I reported and having a better error message there might also be a good thing
pypa/packaging#434

@radarhere
Copy link
Member

The plan is for the next version of Pillow to return "ImportError: The _imagingft C module is not installed" instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants