如何安装 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 开发人员的新手,无法查看此软件包并知道如何安装它并在我的项目中使用它。

请帮忙!

update 我试图创建一个应用程序文件夹,并将此组件作为一个应用程序列在应用程序列表中,但是当我 运行 启动应用程序的代码时,我收到以下错误:

Library not loaded: @rpath/libPDFNetC.dylib

我将所有的 lib 文件放入项目中的这个文件夹中:

我在 py 文件的顶部使用了以下导入代码,我试图在上面使用该组件:

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

我将 lib 文件放入名为 pdfnetc 的应用程序文件夹中。一旦我有了这个,导入语句就不再被 pycharm.

列为未找到

这里是堆栈跟踪:

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

我不了解 django,但请仔细查看 SDK 中的示例 py 文件。例如,查看 PDFNetC/Samples/AddImageTest/PYTHON 文件夹。里面有一个.py文件,看前4行代码,就是需要加载什么。

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

如果这没有帮助,请 post 您收到的确切(第一条)错误消息。

当我尝试 运行 shell 脚本时,它对我来说工作正常,顺便说一句,我使用 python 作为我的 pdfnet 编程语言,

尝试使用这些命令来运行 pdfn

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

PDFATest指定了python代码,然后导出会得到需要的包比如PDFNet在

../../Lib

文件夹,因此请确保您在 lib 中使用该文件,然后在 运行 您的代码中使用 PDFNet 不会有任何问题,顺便说一句,我不会就 django 回答这个问题,但可以肯定这会对您有所帮助出。

以下是安装 PDFNet 模块的步骤:

  1. 下载 Python 和 Ruby 预构建的二进制文件。确保为您的 Python 解释器下载正确的架构。
  2. 解压缩下载的 zip 文件并导航到它。
  3. 导航到Python SDK下载的/PDFNetC/Lib目录并执行:
> chmod a+x fix_rpaths.sh
./fix_rpaths.sh

python -m pip install PDFNetPython3 home page link here