Freetype library not found问题详解,python(编程语言)+freetype(字体引擎)opencv 中文显示

来源:互联网 发布:网页打开淘宝app 编辑:程序博客网 时间:2024/06/07 07:20

环境配置

win7 +python2.7.13+freetype-py-1.0.2

现象

win7环境下pip下载的freetype-py-1.0.2是linux的包,安装后,不能正常使用

原因

pip install freetype-py安装freetype-py-1.0.2后,dll在pip.exe同级目录的Lib\site-packages 文件夹下

cmd

C:\ProgramData\Anaconda2>pip install freetype-pyCollecting freetype-pyInstalling collected packages: freetype-pySuccessfully installed freetype-py-1.0.2

C:\ProgramData\Anaconda2>pythonPython 2.7.13 |Anaconda 4.4.0 (32-bit)| (default, May 11 2017, 14:07:41) [MSC v.1500 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.Anaconda is brought to you by Continuum Analytics.Please check out: http://continuum.io/thanks and https://anaconda.org>>> import freetypeTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "C:\ProgramData\Anaconda2\lib\site-packages\freetype\__init__.py", line 21, in <module>    from freetype.raw import *  File "C:\ProgramData\Anaconda2\lib\site-packages\freetype\raw.py", line 37, in <module>    raise RuntimeError('Freetype library not found')RuntimeError: Freetype library not found
raw.py

line 37>if platform.system() == 'Windows':

# -*- coding: utf-8 -*-# -----------------------------------------------------------------------------#  FreeType high-level python API - Copyright 2011-2015 Nicolas P. Rougier#  Distributed under the terms of the new BSD license.# -----------------------------------------------------------------------------'''Freetype raw APIThis is the raw ctypes freetype binding.'''import osimport platformfrom ctypes import *import ctypes.utilfrom freetype.ft_types import *from freetype.ft_enums import *from freetype.ft_errors import *from freetype.ft_structs import *# on windows all ctypes does when checking for the library# is to append .dll to the end and look for an exact match# within any entry in PATH.filename = ctypes.util.find_library('freetype')if filename is None:    if platform.system() == 'Windows':        # Check current working directory for dll as ctypes fails to do so        filename = os.path.join(os.path.realpath('.'), 'freetype.dll')    else:        filename = 'libfreetype.so.6'try:    _lib = ctypes.CDLL(filename)except (OSError, TypeError):    _lib = None    raise RuntimeError('Freetype library not found')FT_Init_FreeType       = _lib.FT_Init_FreeTypeFT_Done_FreeType       = _lib.FT_Done_FreeTypeFT_Library_Version     = _lib.FT_Library_Versiontry:    FT_Library_SetLcdFilter= _lib.FT_Library_SetLcdFilterexcept AttributeError:    def FT_Library_SetLcdFilter (*args, **kwargs):        return 0try:    FT_Library_SetLcdFilterWeights = _lib.FT_Library_SetLcdFilterWeightsexcept AttributeError:    passFT_New_Face            = _lib.FT_New_FaceFT_New_Memory_Face     = _lib.FT_New_Memory_FaceFT_Open_Face           = _lib.FT_Open_FaceFT_Attach_File         = _lib.FT_Attach_FileFT_Attach_Stream       = _lib.FT_Attach_Streamtry:    FT_Reference_Face      = _lib.FT_Reference_Faceexcept AttributeError:passFT_Done_Face           = _lib.FT_Done_FaceFT_Done_Glyph          = _lib.FT_Done_GlyphFT_Select_Size         = _lib.FT_Select_SizeFT_Request_Size        = _lib.FT_Request_SizeFT_Set_Char_Size       = _lib.FT_Set_Char_SizeFT_Set_Pixel_Sizes     = _lib.FT_Set_Pixel_SizesFT_Load_Glyph          = _lib.FT_Load_GlyphFT_Load_Char           = _lib.FT_Load_CharFT_Set_Transform       = _lib.FT_Set_TransformFT_Render_Glyph        = _lib.FT_Render_GlyphFT_Get_Kerning         = _lib.FT_Get_KerningFT_Get_Track_Kerning   = _lib.FT_Get_Track_KerningFT_Get_Glyph_Name      = _lib.FT_Get_Glyph_NameFT_Get_Glyph           = _lib.FT_Get_GlyphFT_Glyph_Get_CBox      = _lib.FT_Glyph_Get_CBoxFT_Get_Postscript_Name = _lib.FT_Get_Postscript_NameFT_Get_Postscript_Name.restype = c_char_pFT_Select_Charmap      = _lib.FT_Select_CharmapFT_Set_Charmap         = _lib.FT_Set_CharmapFT_Get_Charmap_Index   = _lib.FT_Get_Charmap_IndexFT_Get_CMap_Language_ID= _lib.FT_Get_CMap_Language_IDFT_Get_CMap_Format     = _lib.FT_Get_CMap_FormatFT_Get_Char_Index      = _lib.FT_Get_Char_IndexFT_Get_First_Char      = _lib.FT_Get_First_CharFT_Get_Next_Char       = _lib.FT_Get_Next_CharFT_Get_Name_Index      = _lib.FT_Get_Name_IndexFT_Get_SubGlyph_Info   = _lib.FT_Get_SubGlyph_Infotry:    FT_Get_FSType_Flags    = _lib.FT_Get_FSType_Flags    FT_Get_FSType_Flags.restype  = c_ushortexcept AttributeError:passFT_Get_X11_Font_Format = _lib.FT_Get_X11_Font_FormatFT_Get_X11_Font_Format.restype = c_char_pFT_Get_Sfnt_Name_Count = _lib.FT_Get_Sfnt_Name_CountFT_Get_Sfnt_Name       = _lib.FT_Get_Sfnt_NameFT_Get_Advance         = _lib.FT_Get_AdvanceFT_Outline_GetInsideBorder  = _lib.FT_Outline_GetInsideBorderFT_Outline_GetOutsideBorder = _lib.FT_Outline_GetOutsideBorderFT_Outline_Get_BBox         = _lib.FT_Outline_Get_BBoxFT_Outline_Get_CBox         = _lib.FT_Outline_Get_CBoxFT_Stroker_New              = _lib.FT_Stroker_NewFT_Stroker_Set              = _lib.FT_Stroker_SetFT_Stroker_Rewind           = _lib.FT_Stroker_RewindFT_Stroker_ParseOutline     = _lib.FT_Stroker_ParseOutlineFT_Stroker_BeginSubPath     = _lib.FT_Stroker_BeginSubPathFT_Stroker_EndSubPath       = _lib.FT_Stroker_EndSubPathFT_Stroker_LineTo           = _lib.FT_Stroker_LineToFT_Stroker_ConicTo          = _lib.FT_Stroker_ConicToFT_Stroker_CubicTo          = _lib.FT_Stroker_CubicToFT_Stroker_GetBorderCounts  = _lib.FT_Stroker_GetBorderCountsFT_Stroker_ExportBorder     = _lib.FT_Stroker_ExportBorderFT_Stroker_GetCounts        = _lib.FT_Stroker_GetCountsFT_Stroker_Export           = _lib.FT_Stroker_ExportFT_Stroker_Done             = _lib.FT_Stroker_DoneFT_Glyph_Stroke             = _lib.FT_Glyph_StrokeFT_Glyph_StrokeBorder       = _lib.FT_Glyph_StrokeBorderFT_Glyph_To_Bitmap          = _lib.FT_Glyph_To_Bitmap

解决办法

目录C:\ProgramData\Anaconda2\Lib\site-packages\freetype下的raw.py文件修改导入freetype.dll的路径

filename = os.path.join(os.path.realpath('.'), 'freetype.dll')

#路径是不freetype.dll实际安装的路径

调整为

filename = "C:\\ProgramData\\Anaconda2\\Lib\\site-packages\\freetype.dll"
请根据实际freetype.dll位置配置路径。

验证

方法一

cmd中输入python
>python
>import freetype
执行成功说明配置成功。

方法二

1.建立文件

C:\ProgramData\Anaconda2目录下建立 ft.py文件(编码utf-8)
import freetypeface = freetype.Face("msyh.ttf")#微软雅黑face.set_char_size( 48*64 )face.load_char('S')bitmap = face.glyph.bitmapprint bitmap.buffer

2.执行

cmd进入C:\ProgramData\Anaconda2目录,
>python ft.py

3.执行成功


4.执行输出

C:\ProgramData\Anaconda2>python ft.py[0, 0, 0, 0, 0, 0, 0, 55, 122, 173, 215, 233, 248, 248, 234, 215, 170, 119, 35,0, 0, 0, 0, 0, 0, 0, 0, 5, 110, 216, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 183, 33, 0, 0, 0, 0, 0, 59, 215, 255, 255, 255, 255, 255, 255,255, 255, 255, 255, 255, 255, 255, 255, 255, 244, 0, 0, 0, 0, 88, 249, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 66, 254, 255, 255, 255, 255, 254, 182, 98, 46, 16, 3, 13, 28, 59, 108, 168, 245, 255, 255, 0, 0, 12, 226, 255, 255, 255, 255, 215, 50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 108, 234, 0, 0, 97, 255, 255, 255, 255, 222, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 184, 255, 255, 255, 255, 89, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 224, 255, 255, 255, 255, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 248, 255, 255, 255, 255, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 240, 255, 255, 255, 255, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 204, 255, 255, 255, 255, 139, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 134, 255, 255, 255, 255, 250, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 250, 255, 255, 255, 255, 251, 121, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 129, 255, 255, 255, 255, 255, 255, 211, 71, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 169, 255, 255, 255, 255, 255,255, 255, 189, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 142, 255, 255, 255, 255, 255, 255, 255, 255, 191, 66, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 75, 224, 255, 255, 255, 255, 255, 255, 255, 255, 196, 67, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 132, 245, 255, 255, 255, 255, 255, 255, 255, 255, 177, 34, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 143, 246, 255, 255, 255, 255, 255, 255, 255, 247, 105, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 138, 242, 255, 255, 255, 255, 255, 255, 255, 164, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 19, 133, 244, 255,255, 255, 255, 255, 255, 174, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23, 157, 255, 255, 255, 255, 255, 255, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 80, 241, 255, 255, 255, 255, 247, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 66, 249, 255, 255, 255, 255, 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 145, 255, 255, 255, 255, 203, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 45, 255, 255, 255, 255, 238, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 255, 255, 255, 255, 247, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 22, 255, 255, 255, 255, 222, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 85, 255, 255, 255, 255, 187, 215, 62, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 210, 255, 255, 255, 255, 106, 255, 255, 187, 77, 5, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 26, 189, 255, 255, 255, 255, 239, 20, 255, 255, 255, 255, 238, 176, 115, 59, 34, 12, 4, 15, 43, 87, 160, 246, 255, 255, 255, 255, 255, 95, 0, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 132, 0, 0, 53, 215, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 238, 98, 0, 0, 0, 0, 5, 96, 202, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 230, 137, 18, 0, 0, 0, 0, 0, 0, 0, 0, 31, 96, 160, 207, 232, 251, 243, 229, 212, 171, 125, 64, 2, 0,0, 0, 0, 0, 0]C:\ProgramData\Anaconda2>






原创粉丝点击