【问题标题】:WEASYPRINT M1 MAC MINIWEASYPRINT M1 MAC MINI
【发布时间】:2022-01-14 07:22:28
【问题描述】:

我正在运行 weasyprint 但系统找不到包:

(env) andrestemmett@Andres-Mac-mini MicrocareERP % weasyprint --info 回溯(最近一次通话最后): 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/bin/weasyprint”,第 5 行,在 从 weasyprint.__main__ 进口主要 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/__init__.py”,第 322 行,在 从 .css 导入 preprocess_stylesheet # noqa isort:skip 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/css/__init__.py”,第 27 行,在 从 。导入计算值、计数器、媒体查询 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/css/computed_values.py”,第 16 行,在 从 ..text.ffi 导入 ffi、pango、units_to_double 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/text/ffi.py”,第 380 行,在 gobject = _dlopen( _dlopen 中的文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/weasyprint/text/ffi.py”,第 377 行 return ffi.dlopen(names[0]) # pragma: no cover 文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py”,第 150 行,在 dlopen lib, function_cache = _make_ffi_library(self, name, flags) _make_ffi_library 中的文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py”,第 832 行 backendlib = _load_backend_lib(后端,libname,标志) _load_backend_lib 中的文件“/Users/andrestemmett/Desktop/MicrocareERP/env/lib/python3.9/site-packages/cffi/api.py”,第 827 行 引发 OSError(msg) OSError: 无法加载库 'gobject-2.0-0': dlopen(gobject-2.0-0, 2): image not found。此外,ctypes.util.find_library() 无法找到名为“gobject-2.0-0”的库

我试图将我的符号链接更改为链接到 hombrew,因为我读到 weasy print 依赖于依赖项 pango libffi。但是,当我尝试这样做时:

sudo ln -s /opt/homebrew/opt/glib/lib/libgobject-2.0.0.dylib /usr/local/lib/gobject-2.0 sudo ln -s /opt/homebrew/opt/pango/lib/libpango-1.0.dylib /usr/local/lib/pango-1.0 sudo ln -s /opt/homebrew/opt/harfbuzz/lib/libharfbuzz.dylib /usr/local/lib/harfbuzz sudo ln -s /opt/homebrew/opt/fontconfig/lib/libfontconfig.1.dylib /usr/local/lib/fontconfig-1 sudo ln -s /opt/homebrew/opt/pango/lib/libpangoft2-1.0.dylib /usr/local/lib/pangoft2-1.0

然后我得到这个错误:

ln: /usr/local/lib/gobject-2.0: 没有这样的文件或目录 ln: /usr/local/lib/pango-1.0: 没有这样的文件或目录 ln: /usr/local/lib/harfbuzz: 没有这样的文件或目录 ln: /usr/local/lib/fontconfig-1: 没有那个文件或目录 ln: /usr/local/lib/pangoft2-1.0: 没有这样的文件或目录

我不明白,因为我读到这是我的系统将查找包的地方,但这个位置不存在。

请帮忙!!我绝望了哈哈

【问题讨论】:

    标签: django weasyprint


    【解决方案1】:

    符号链接可能不起作用,因为目录 /usr/local/lib/ 不存在。

    要解决此问题,请运行

    mkdir /usr/local/lib/
    

    【讨论】:

      【解决方案2】:

      所以我最终使用了 xhtml2pdf,它实现起来超级简单快捷。

      pip 安装 xhtml2pdf

      从 django.http 导入 HttpResponse 从 django.template.loader 导入 get_template 从 xhtml2pdf 导入比萨

      def 下载PDF(request,pk): queryOrderPlan = OrderPlan.objects.get(id=pk) queryItems = queryOrderPlan.orderitem_set.all() template_path = 'orderApp/pdfs/itempdf.html' 上下文 = {"queryItems":queryItems,} 响应 = HttpResponse(content_type='application/pdf') response['content-disposition'] = '附件;文件名="items.pdf"' 模板 = 获取模板(模板路径) html = template.render(上下文) pisa_status = pisa.CreatePDF(html, dest=response) 如果 pisa_status.err: return HttpResponse("我们有一些错误
      " + html + "
      ")
          return response
      

      【讨论】:

      • 剩下的就看你的html和css了!要获取图像,请使用 {{query.image.path}} 如果您从模型中获取它,而不是 url。
      猜你喜欢
      • 1970-01-01
      • 2021-08-12
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 1970-01-01
      • 2021-04-10
      • 2021-03-25
      • 1970-01-01
      相关资源
      最近更新 更多