【发布时间】:2018-10-05 07:41:01
【问题描述】:
打包为 exe 时如何强制 pyinstaller 使用特定的 .jar 文件?
我正在尝试生成一个使用 tabula-py lib 的可执行文件。这个库需要一个 jar 文件,tabula-1.0.1-jar-with-dependencies.jar,我的 file.py 文件夹中有该文件。以下是 myfile.spec 中的一些修改:
# this is for pandas lib
def get_pandas_path():
import pandas
pandas_path = pandas.__path__[0]
return pandas_path
dict_tree = Tree(get_pandas_path(), prefix='pandas', excludes=["*.pyc"])
a.datas += dict_tree
a.binaries = filter(lambda x: 'pandas' not in x[0], a.binaries)
# this is for tabula-py
jar = 'tabula-1.0.1-jar-with-dependencies'
jar_path = 'C:\\Users\\jaquedeveloper\\Documents\\freelancer\\bot\\' + jar
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
[(jar, jar_path, 'PKG')],
strip=None,
upx=True,
name='test')
不过,错误仍然存在。 当我从命令行运行我的代码时,使用 java jar 的 tabula-py 中的函数 read_pdf() 可以正常工作。
但是当我使用 pyinstaller spec 命令生成可执行文件时,它无法执行此功能,并给出以下错误:
无法访问 jarfile C:\Users\jaquedeveloper\AppData\Local\Temp_MEI58442\tabula\tabula-1.0.1-jar-with-dependencies.jar
该文件不在此文件夹下,tabula 文件夹也不存在。 我在可执行文件的同一文件夹下有文件。如何强制脚本使用它? 如何将 jar 从特定路径导入可执行文件,而不是使用 _MEI 文件夹?
here也报告了这个问题。
【问题讨论】:
-
嗨,杰奎琳。你有没有运气找到这个问题的答案?我也有类似的问题。
-
不走运,由于客户请求,我最终没有开发该功能,并且没有做任何事情,因为他们......我已经生成了一个 exe,但没有使用 tabula,因为没有更多必要过滤pdf文件。
-
好的。谢谢你让我知道。我最终使用 Camelot-py 而不是 Tabula 重写了我的程序,这样没有管理员权限的用户可以在没有 Java 的情况下运行它。
标签: java python jar pyinstaller