簡體   English   中英

如何安裝 PDFNet python 模塊?

[英]How do I install PDFNet python module?

我一直在試圖弄清楚如何讓我的 Django 應用程序識別 PDFNet 的試用版:

https://pypi.python.org/pypi/PDFTron-PDFNet-SDK-for-Python/5.7

我嘗試將文件添加到我的 ~/usr/bin 目錄中,我嘗試將它們放入我的 virtualenv 的 bin 目錄中。 兩者都沒有奏效。 我已經閱讀了我能找到的所有文檔。 我是 Python 開發人員的新手,無法查看此包並知道如何安裝它並在我的項目中使用它。

請幫忙!

更新我試圖創建一個應用程序文件夾,並在應用程序列表中將此組件列為應用程序,但是當我運行代碼以啟動應用程序時,出現以下錯誤:

庫未加載:@rpath/libPDFNetC.dylib

我將所有的 lib 文件放在我的項目中的這個文件夾中:

  • __init.py(空)
  • _PDFNetPython.so
  • libPDFNetC.dylib
  • PDFNetPython.py
  • PDFNetRuby.bundle

我在嘗試使用該組件的 py 文件頂部使用了以下導入代碼:

import site
site.addsitedir("../pdfnetc")
from pdfnetc.PDFNetPython import *

我將 lib 文件放入名為 pdfnetc 的應用程序文件夾中。 一旦我有了這個,導入語句就不再被 pycharm 列為 unfound 。

這是堆棧跟蹤:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2217, in <module>
    globals = debugger.run(setup['file'], None, None)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1643, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/ntregillus/myapp/manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/ntregillus/Envs/myapp/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/ntregillus/myapp/statements/models.py", line 12, in <module>
    from statements.managers import StatementTemplateManager, StatementManager
  File "/Users/ntregillus/myapp/statements/managers.py", line 8, in <module>
    from statements.utils import render_to_pdf, StatementContextBuilder
  File "/Users/ntregillus/myapp/statements/utils.py", line 23, in <module>
    from pdfnetc.PDFNetPython import *
  File "/Users/ntregillus/myapp/pdfnetc/PDFNetPython.py", line 28, in <module>
    _PDFNetPython = swig_import_helper()
  File "/Users/ntregillus/myapp/pdfnetc/PDFNetPython.py", line 24, in swig_import_helper
    _mod = imp.load_module('_PDFNetPython', fp, pathname, description)
ImportError: dlopen(/Users/ntregillus/myapp/pdfnetc/_PDFNetPython.so, 2): Library not loaded: @rpath/libPDFNetC.dylib
  Referenced from: /Users/ntregillus/myapp/pdfnetc/_PDFNetPython.so
  Reason: image not found

python -m pip install PDFNetPython3 主頁鏈接在這里

以下是安裝 PDFNet 模塊的步驟:

  1. 下載 Python 和 Ruby 預構建的二進制文件。 確保為 Python 解釋器下載正確的架構。
  2. 解壓縮下載的 zip 文件並導航到它。
  3. 導航到 Python SDK 下載的 /PDFNetC/Lib 目錄並執行:
> chmod a+x fix_rpaths.sh
./fix_rpaths.sh

我不了解 django,但請仔細查看 SDK 中的示例 py 文件。 例如,查看 PDFNetC/Samples/AddImageTest/PYTHON 文件夾。 里面有一個 .py 文件,看看前 4 行代碼,它們表明需要加載什么。

請注意,您需要 PDFNetC/Lib 文件夾中的所有文件,包括 PDFNetC.dll 文件。

如果這沒有幫助,請發布您收到的確切(第一條)錯誤消息。

當我嘗試運行 shell 腳本時,它對我來說很好用,順便說一句,我使用 python 作為我的 pdfnet 編程語言,

嘗試使用這些命令來運行 pdfn

#!/bin/sh
TEST_NAME=PDFATest
export LD_LIBRARY_PATH=../../../PDFNetC/Lib
python -u $TEST_NAME.py

PDFATest指定python代碼,然后導出會得到需要的包,比如里面的PDFNet

../../庫

文件夾,因此請確保您在 lib 中使用該文件,然后運行您的代碼,並且您不會對 PDFNet 有任何問題,順便說一句,我不會就 django 回答這個問題,但確保這會對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM