Repository: mindee/doctr

Issue:
WeasyPrint import error Python 3.7
## 🐛 Bug

When importing weasyprint with python 3.7 I have an error: `AttributeError: 'OutStream' object has no attribute 'buffer'`*


## To Reproduce

Steps to reproduce the behavior:

`from doctr.models import ocr_predictor`

leads to:

```
AttributeError                            Traceback (most recent call last)

<ipython-input-4-19f78ebc9b57> in <module>()
----> 1 from doctr.models import ocr_predictor
      2 
      3 # Load predictor
      4 model = ocr_predictor(pretrained=True)

7 frames

/usr/local/lib/python3.7/dist-packages/doctr/__init__.py in <module>()
      1 from .file_utils import is_tf_available, is_torch_available
      2 from .version import __version__  # noqa: F401
----> 3 from . import documents
      4 from . import transforms
      5 from . import utils

/usr/local/lib/python3.7/dist-packages/doctr/documents/__init__.py in <module>()
      1 from .elements import *
----> 2 from .reader import *

/usr/local/lib/python3.7/dist-packages/doctr/documents/reader.py in <module>()
      8 from pathlib import Path
      9 import fitz
---> 10 from weasyprint import HTML
     11 from typing import List, Tuple, Optional, Any, Union, Sequence, Dict
     12 

/usr/local/lib/python3.7/dist-packages/weasyprint/__init__.py in <module>()
    321 # Work around circular imports.
    322 from .css import preprocess_stylesheet  # noqa isort:skip
--> 323 from .html import (  # noqa isort:skip
    324     HTML5_UA_COUNTER_STYLE, HTML5_UA_STYLESHEET, HTML5_PH_STYLESHEET,
    325     find_base_url)

/usr/local/lib/python3.7/dist-packages/weasyprint/html.py in <module>()
     21 from .css.counters import CounterStyle
     22 from .formatting_structure import boxes
---> 23 from .images import SVGImage
     24 from .logger import LOGGER
     25 from .urls import get_url_attribute

/usr/local/lib/python3.7/dist-packages/weasyprint/images.py in <module>()
     11 from itertools import cycle
     12 
---> 13 import pydyf
     14 from PIL import Image
     15 

/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in <module>()
    402 
    403 
--> 404 class PDF:
    405     """PDF document."""
    406     def __init__(self):

/usr/local/lib/python3.7/dist-packages/pydyf/__init__.py in PDF()
    506         self.write_line(b'%%EOF', output)
    507 
--> 508     def write(self, output=sys.stdout.buffer):
    509         """Write PDF to output.
    510 

AttributeError: 'OutStream' object has no attribute 'buffer'

```


## Expected behavior

Nothing, special

## Environment
```
DocTR version: 0.3.0
TensorFlow version: 2.5.0
PyTorch version: 1.9.0+cu102 (torchvision 0.10.0+cu102)
OpenCV version: 4.5.3
OS: Ubuntu 18.04.5 LTS
Python version: 3.7
Is CUDA available (TensorFlow): No
Is CUDA available (PyTorch): No
CUDA runtime version: 11.0.221
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
```



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -49,7 +49,7 @@
     "shapely>=1.6.0",
     "matplotlib>=3.1.0",
     "mplcursors>=0.3",
-    "weasyprint>=52.2",
+    "weasyprint>=52.2,<53.0",
     "unidecode>=1.0.0",
     "tensorflow-cpu>=2.4.0",
     "torch>=1.8.0",


Test patch: