# Module 'cv2' has no attribute 'freetype'

**URL:** <https://forum.opencv.org/t/module-cv2-has-no-attribute-freetype/12489>\
**Category:** Python\
**Tags:** contrib\
**Created:** [March 22, 2023, 11:25pm UTC](https://forum.opencv.org/t/module-cv2-has-no-attribute-freetype/12489 "2023-03-22T23:25:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shawn\_McDonald](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/shawn_mcdonald/32/7472_2.png) [@Shawn\_McDonald](https://forum.opencv.org/u/Shawn_McDonald)\
**Post date:** [March 22, 2023, 11:25pm UTC](https://forum.opencv.org/t/module-cv2-has-no-attribute-freetype/12489/1 "2023-03-22T23:25:36Z")

</div>

Here is a quick sample code

```auto
import cv2
import numpy as np

img = np.zeros((100, 300, 3), dtype=np.uint8)

ft = cv2.freetype.createFreeType2()
ft.loadFontData(fontFileName='Ubuntu-R.ttf',
                id=0)
ft.putText(img=img,
           text='Quick Fox',
           org=(15, 70),
           fontHeight=60,
           color=(255, 255, 255),
           thickness=-1,
           line_type=cv2.LINE_AA,
           bottomLeftOrigin=True)

cv2.imwrite('image.png', img)

```

The above example works fine if I build OpenCV from source, however, if I use the pip install opencv-contrib-python or pip install opencv-python, I get error 'module ‘cv2’ has no attribute ‘freetype’ ’

Any recommendations? Or do I just need to build OpenCV?

Thanks!

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [March 23, 2023, 6:45am UTC](https://forum.opencv.org/t/module-cv2-has-no-attribute-freetype/12489/2 "2023-03-23T06:45:24Z")

</div>

I think the answer is [here](http://freetype.org/license.html)  
licenses problem

> the [FreeType License](https://gitlab.freedesktop.org/freetype/freetype/-/blob/master/docs/FTL.TXT) (FTL) is the most commonly used one. It is a BSD-style license with a credit clause and thus compatible with the GNU Public License (GPL) version 3, but not with the GPL version 2.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 23, 2023, 2:00pm UTC](https://forum.opencv.org/t/module-cv2-has-no-attribute-freetype/12489/4 "2023-03-23T14:00:57Z")

</div>

it’s actually here:

> <https://github.com/opencv/opencv-python/issues/243>
>
> \### Expected behaviour
> 
> I'm trying to use cv2 with freetype and all the docume…ntation basically says that you just need to \`pip install opencv-contrib-python\` in order to get this to work. But it throws an AttributeError on this line: \`free\_type = cv2.freetype.createFreeType2()\`
> 
> \### Actual behaviour
> 
> AttributeError when trying to access freetype
> 
> \### Steps to reproduce
> 
> \- Create a new python file
> \- create a new conda env
> \- \`pip install opencv-contrib-python\`
> 
> \`\`\`
> import cv2
> 
> free\_type = cv2.freetype.createFreeType2()
> \`\`\`
> \- operating system: Ubuntu
> \- opencv-python version: opencv-contrib-python==4.1.1.26

the +contrib binary package _does_ contain some stuff that may have licensing issues, but not everything.

usually it’s a matter of how difficult those libraries (freetype, harfbuzz, …) make it to build against them.
