我正在尝试将Py2app的python文件转换为Mac应用程序。
在这个文件中,我使用fpdf2编写不同的pdf格式,但是看起来我在这个包和py2app的使用上有一些问题。
这就是为什么我在一个非常小的地方测试它的原因,我只使用fpdf2程序:
test = "test"
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font('times', size=20)
pdf.cell(0, 12, txt="Test", ln=True, align='L')
pdf.output('test.pdf')使用此setup.py文件:
from setuptools import setup
APP = ['test for compile.py']
OPTIONS = {
'argv_emulation': True,
}
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)在这里我得到了同样的错误信息:
Traceback (most recent call last):
File "-/test_for_compile/dist/test for compile.app/Contents/Resources/__boot__.py", line 463, in <module>
_run()
File "-/test_for_compile/dist/test for compile.app/Contents/Resources/__boot__.py", line 457, in _run
exec(compile(source, script, "exec"), globals(), globals())
File "-/test_for_compile/test for compile.py", line 2, in <module>
from fpdf import FPDF
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/fpdf/__init__.py", line 4, in <module>
from .fpdf import (
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/fpdf/fpdf.py", line 37, in <module>
from PIL import Image
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/Image.py", line 89, in <module>
from . import _imaging as core
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_jpeg_resync_to_restart'
2022-02-21 14:53:48.261 test for compile[6126:387824] Launch error
2022-02-21 14:53:48.261 test for compile[6126:387824] Launch error
See the py2app website for debugging launch issues在https://py2app.readthedocs.io/en/latest/debugging.html上,他们为导入问题编写了以下内容:
一些常见的问题是:
由于缺少模块或包,导入语句失败。
这通常发生在源代码分析器无法找到依赖项时,>由于动态导入(使用导入()或导入库加载模块),或者由于C扩展中的导入。
这里有更详细的https://py2app.readthedocs.io/en/latest/options.html
但老实说,如果他们现在是我的问题,以及我能做些什么来解决问题,我就不明白了。
因此,我真的很高兴得到一些帮助:)
发布于 2022-03-15 01:39:00
错误ImportError: dlopen通常意味着您的setup.py文件中有错误。在您的例子中,您导入了包"fpdf“和"FPDF”,但没有将它们包含在应用程序构建中。
这里是您的setup.py应该是什么样子:
from setuptools import setup
APP = ['test.py']
DATA_FILES = ['fpdf','FPDF']
OPTIONS = {
'argv_emulation': False,
}
setup(
app=APP,
data_files = DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
如果右键单击"dist“文件夹中的test.app文件并单击”“,您将看到test.pdf文件位于Content> Resources > test.pdf中。
https://stackoverflow.com/questions/71208039
复制相似问题