'Py2App - ImportError: dlopen
I'm trying to convert a python file by Py2app to a Mac OS app.
In this file I'm using fpdf2 to write in different pdf's, but looks like I have some problems with this package and the use of py2app.
Thats why I tested it with a really small where I just use fpdf2 program:
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')
With this setup.py file:
from setuptools import setup
APP = ['test for compile.py']
OPTIONS = {
'argv_emulation': True,
}
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
And there I get the same Error message:
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
On https://py2app.readthedocs.io/en/latest/debugging.html they write following to import problems:
Some common problems are:
An import statement fails due to a missing module or package
This generally happens when the dependency cannot be found by the source code analyzer, > either due to dynamic imports (using import() or importlib to load a module), or due to imports in a C extension.
And here more detailed https://py2app.readthedocs.io/en/latest/options.html
But to be honest I don't get if they mean now my problem, and what I can do to solve it.
So I would be really happy for some help :)
Solution 1:[1]
The error ImportError: dlopen often means you have a mistake in your setup.py file. In your case, you imported the packages "fpdf" and "FPDF" but did not include them in your app build.
Here is what your setup.py should look like:
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'],
)
If you right-click the test.app file in your "dist" folder and click "show package contents", you will see that the test.pdf file will be in Contents > Resources > test.pdf.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ks08 |
