PyPandoc与PyInstaller结合使用

时间:2016-08-10 13:15:38

标签: python pyinstaller pandoc pypandoc

我安装了PyInstaller来为我的python脚本创建可执行文件,并且工作正常。我使用PyPandoc创建unittest.TestCase报告,这些报告在运行普通python文件时运行正常,但不是从PyInstaller生成的可执行文件运行。它给出了错误:

Failure
Traceback (most recent call last):
  File "/git/bitex/tests/client_tests.py", line 39, in test_restapi_nonce
    int(n)
ValueError: invalid literal for int() with base 10: 'a'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "//git/bitex/tests/client_tests.py", line 41, in test_restapi_nonce
    self.fail("%s is not a stringified integer!" % n)
AssertionError: a is not a stringified integer!

在可执行文件创建过程中,我发现没有关于PyPandoc的奇怪问题。如何将Pandoc包含在我的可执行文件中,以便其他人(没有安装Python和/或Pandoc)可以使用可执行文件并创建.docx报告?

编辑:工作流程包括以下步骤:

  1. 创建一个包含以下代码的文件:

    Traceback (most recent call last):
      File "src\flexmodel_postcalc.py", line 295, in postcalculate_everything
      File "src\flexmodel_postcalc.py", line 281, in generate_report_docx
      File "src\flexmodel_report_docx.py", line 118, in generate_text_useages_docx
      File "pypandoc\__init__.py", line 50, in convert
      File "pypandoc\__init__.py", line 70, in _convert
      File "pypandoc\__init__.py", line 197, in get_pandoc_formats
      File "pypandoc\__init__.py", line 336, in _ensure_pandoc_path
    OSError: No pandoc was found: either install pandoc and add it
    to your PATH or install pypandoc wheels with included pandoc.
    
  2. 将此文件另存为.docx

  3. 使用PyInstaller创建一个可执行文件:

    import pypandoc
    pypandoc.convert(sou‌​rce='# Sample title\nPlaceholder', to='docx', format='md', outputfile='test.doc‌​x')
    
  4. 现在,可执行文件应该在没有安装Pandoc(或PyPandoc)的计算机上运行。

0 个答案:

没有答案