这里有两个问题。第一个是pypandoc
needs pandoc.exe
上班。这不是由pyinstaller
自动,但您可以手动指定。
要做到这一点,你必须创建一个.spec file https://pythonhosted.org/PyInstaller/spec-files.html#using-spec-files。我生成并使用的看起来像这样:
block_cipher = None
a = Analysis(['pythonfile.py'],
pathex=['CodeDIR'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
name='EXEName',
debug=False,
strip=False,
upx=True,
console=True ,
resources=['YourPandocLocationHere\\\\pandoc.exe'])
您可以使用以下方式构建可执行文件pyinstaller myspec.spec
。不要忘记更改路径和name
范围。
如果您在目录模式下构建它,这应该足够了。然而,对于one-file
模式,由于 pyinstaller 的方式,事情有点复杂引导加载程序进程 https://pythonhosted.org/PyInstaller/advanced-topics.html#bootloader作品。这pandoc.exe
文件在执行期间解压缩到临时文件夹中,但执行发生在原始文件夹中.exe
文件夹。根据这个问题 https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile,如果您运行冻结的代码,则必须在调用 pypandoc 更改当前文件夹之前将以下行添加到代码中。
if hasattr(sys, '_MEIPASS'):
os.chdir(sys._MEIPASS)