Debian Codegraph @

docs/en/reference/platforms/linux/appimage.md

raw
1 # AppImage
2
3 <table class="host-platform-support-table">
4 <colgroup>
5 <col style="width: 11%" />
6 <col style="width: 10%" />
7 <col style="width: 7%" />
8 <col style="width: 5%" />
9 <col style="width: 6%" />
10 <col style="width: 5%" />
11 <col style="width: 5%" />
12 <col style="width: 7%" />
13 <col style="width: 11%" />
14 <col style="width: 7%" />
15 <col style="width: 10%" />
16 </colgroup>
17 <thead>
18 <tr>
19 <th colspan="11"><a href="../../../../reference/platforms">Host Platform Support</a></th>
20 </tr>
21 <tr>
22 <th colspan="2">macOS</th>
23 <th colspan="5">Windows</th>
24 <th colspan="4">Linux</th>
25 </tr>
26 <tr>
27 <th>x86‑64</th>
28 <th>arm64</th>
29 <th>x86</th>
30 <th colspan="2">x86‑64</th>
31 <th colspan="2">arm64</th>
32 <th>x86</th>
33 <th>x86‑64</th>
34 <th>arm</th>
35 <th>arm64</th>
36 </tr>
37 </thead>
38 <tbody>
39 <tr>
40 <td>{{ not_tested }}</td>
41 <td>{{ not_tested }}</td>
42 <td></td>
43 <td colspan="2"></td>
44 <td colspan="2"></td>
45 <td>{{ not_tested }}</td>
46 <td>{{ not_tested }}</td>
47 <td>{{ not_tested }}</td>
48 <td>{{ not_tested }}</td>
49 </tr>
50 </tbody>
51 </table>
52
53 /// admonition | Best effort support
54
55 AppImage has a number of significant issues building images for GUI apps. It is incompatible with the use of binary wheels, and the use of an older Linux base image for compatibility purposes is incompatible with using modern GUI frameworks. Even when a GUI toolkit *can* be installed, the AppImage packaging process frequently introduces bugs related to DBus integration or libraries like WebKit2 that use subprocesses.
56
57 Briefcase provides an AppImage backend for historical reasons, but we strongly discourage the use of AppImages for distribution. We maintain unit test coverage for the AppImage backend, but we do not build AppImages as part of our release process. We will accept bug reports related to AppImage support, and we will merge PRs that address AppImage support, but the core team does not consider addressing AppImage bugs a priority.
58
59 If you need to distribute a Linux app, [System packages][native-system-packages] or [Flatpaks][flatpak] are much more reliable options.
60
61 ///
62
63 [AppImage](https://appimage.org) provides a way for developers to provide "native" binaries for Linux users. It allow packaging applications for any common Linux based operating system, including Ubuntu, Debian, Fedora, and more. AppImages contain all the dependencies that cannot be assumed to be part of each target system, and will run on most Linux distributions without further modifications. Briefcase uses [Linuxdeploy](https://github.com/linuxdeploy/linuxdeploy) to build the AppImage in the correct format.
64
65 Packaging binaries for Linux is complicated, because of the inconsistent library versions present on each distribution. An AppImage can be executed on *any* Linux distribution with a version of `libc` greater than or equal the version of the distribution where the AppImage was created.
66
67 To ensure that an application is built in an environment that is as compatible as possible, Briefcase builds AppImages inside Docker. The Docker base image used by Briefcase can be configured to any [manylinux](https://github.com/pypa/manylinux) base using the `manylinux` application configuration option; if `manylinux` isn't specified, it falls back to an Ubuntu 18.04 base image. While it is *possible* to build AppImages without Docker, it is highly recommended that you do not, as the resulting AppImages will not be as portable as they could otherwise be.
68
69 /// note | Note
70
71 AppImage works by attempting to autodetect all the libraries that an application requires, copying those libraries into a distribution, and manipulating them to reflect their new locations. This approach *can* work well... but it is also prone to major problems. Python apps (which load their dependencies dynamically) are particularly prone to exposing those flaws.
72
73 Briefcase makes a best-effort attempt to use the AppImage tools to build a binary, but sometimes, the problem lies with AppImage itself. If you have problems with AppImage binaries, you should first check whether the problem is a limitation with AppImage.
74
75 ///
76
77 ## Icon format
78
79 AppImages use `.png` format icons. An application must provide icons in the following sizes:
80
81 - 16px
82 - 32px
83 - 64px
84 - 128px
85 - 256px
86 - 512px
87
88 AppImages do not support splash screens or installer images.
89
90 ## Additional options
91
92 The following options can be provided at the command line when producing AppImages.
93
94 ### `--no-docker`
95
96 Use native execution, rather than using Docker to start a container.
97
98 -8<- "reference/platforms/linux/docker_build_options.md"
99
100 ## Application configuration
101
102 The following options can be added to the `tool.briefcase.app.<appname>.linux.appimage` section of your `pyproject.toml` file.
103
104 ### `manylinux`
105
106 The [manylinux](https://github.com/pypa/manylinux) tag to use as a base image when building the AppImage. Should be one of:
107
108 - `manylinux1`
109 - `manylinux2010`
110 - `manylinux2014`
111 - `manylinux2_24`
112 - `manylinux2_28`
113
114 New projects will default to `manylinux2014`. If an application doesn't specify a [`manylinux`][] value, `ubuntu:18.04` will be used as the base image.
115
116 ### `manylinux_image_tag`
117
118 The specific tag of the `manylinux` image to use. Defaults to `latest`.
119
120 ### `system_requires`
121
122 A list of operating system packages that must be installed for the AppImage build to succeed. If a Docker build is requested, this list will be passed to the Docker context when building the container for the app build. By default, entries should be Ubuntu 18.04 `apt` package requirements. For example:
123
124 ```python
125 system_requires = ['libgirepository1.0-dev', 'libcairo2-dev']
126 ```
127
128 would make the GTK GI and Cairo operating system libraries available to your app.
129
130 If you see errors during `briefcase build` of the form:
131
132 ```python
133 Could not find dependency: libSomething.so.1
134 ```
135
136 but the app works under `briefcase dev`, the problem may be an incomplete `system_requires` definition. The `briefcase build` process generates a new environment that is completely isolated from your development environment, so if your app has any operating system dependencies, they *must* be listed in your `system_requires` definition.
137
138 ### `linuxdeploy_plugins`
139
140 A list of [linuxdeploy plugins](https://docs.appimage.org/packaging-guide/from-source/linuxdeploy-user-guide.html#plugin-system) that you wish to be included when building the AppImage. This is needed for applications that depend on libraries that have dependencies that cannot be automatically discovered by Linuxdeploy. GTK and Qt both have complex runtime resource requirements that can be difficult for Linuxdeploy to identify automatically.
141
142 The [`linuxdeploy_plugins`][] declaration is a list of strings. Briefcase can take plugin definitions in three formats:
143
144 1. The name of a plugin known by Briefcase. One of `gtk` or `qt`.
145 2. A URL where a plugin can be downloaded
146 3. A path to a local plugin file
147
148 If your plugin requires an environment variable for configuration, that environment variable can be provided as a prefix to the plugin declaration, similar to how environment variables can be defined for a shell command.
149
150 For example, the `gtk` plugin requires the `DEPLOY_GTK_VERSION` environment variable. To set this variable with the Briefcase-managed GTK Linuxdeploy plugin, you would define:
151
152 ```python
153 linuxdeploy_plugins = ["DEPLOY_GTK_VERSION=3 gtk"]
154 ```
155
156 Or, if you were using a plugin stored as a local file:
157
158 ```python
159 linuxdeploy_plugins = ["DEPLOY_GTK_VERSION=3 path/to/plugins/linuxdeploy-gtk-plugin.sh"]
160 ```
161
162 ### `dockerfile_extra_content`
163
164 Any additional Docker instructions that are required to configure the container used to build your Python app. For example, any dependencies that cannot be configured with `apt-get` could be installed. `dockerfile_extra_content` is string literal that will be added verbatim to the end of the project Dockerfile.
165
166 Any Dockerfile instructions added by `dockerfile_extra_content` will be executed as the `brutus` user, rather than the `root` user. If you need to perform container setup operations as `root`, switch the container's user to `root`, perform whatever operations are required, then switch back to the `brutus` user - e.g.:
167
168 ```python
169 dockerfile_extra_content = """
170 RUN <first command run as brutus>
171
172 USER root
173 RUN <second command run as root>
174
175 USER brutus
176 """
177 ```
178
179 ## Platform quirks
180
181 ### Use caution with `--update-support`
182
183 Care should be taken when using the `--update-support` option to the `update`, `build` or `run` commands. Support packages in Linux AppImages are overlaid with app content, so it isn't possible to remove all old support files before installing new ones.
184
185 Briefcase will unpack the new support package without cleaning up existing support package content. This *should* work; however, ensure a reproducible release artefacts, it is advisable to perform a clean app build before release.
186
187 ### Apps using WebKit2 are not supported
188
189 WebKit2, the library that provides web widget support, can't currently be deployed with AppImage. WebKit2 uses subprocesses to manage network and rendering requests, but the way it packages and launches these subprocesses isn't currently compatible with AppImage.
190
191 In addition, many of the commonly used `manylinux` base images predate the release of WebKit2. As a result, system packages providing WebKit2 are not available on these base images. `manylinux_2_28` is the earliest supported `manylinux` image that provides WebKit2 support.
192
193 ## Runtime issues with AppImages
194
195 Packaging on Linux is a difficult problem - especially when it comes to binary libraries. The following are some common problems you may see, and ways that they can be mitigated.
196
197 ### Failure to load `libpango-1.0-so.0`
198
199 Older Linux distributions (e.g., Ubuntu 18.04) may not be compatible with AppImages of Toga apps produced by Briefcase, complaining about problems with `libpango-1.0.so.0` and an undefined symbols (`fribidi_get_par_embedding_levels_ex` is a common missing symbol to be reported). This is caused because the version of `fribidi` provided by these distributions. Unfortunately, there's no way to fix this limitation.
200
201 ### Undefined symbol and Namespace not available errors
202
203 If you get the error:
204
205 ```console
206 ValueError: Namespace Something not available
207 ```
208
209 or:
210
211 ```console
212 ImportError: /usr/lib/libSomething.so.0: undefined symbol: some_symbol
213 ```
214
215 it is likely that one or more of the libraries you are using in your app requires a Linuxdeploy plugin. GUI libraries, or libraries that do dynamic module loading are particularly prone to this problem.
216
217 ### ELF load command address/offset not properly aligned
218
219 Briefcase uses a tool named Linuxdeploy to build AppImages. Linuxdeploy processes all the libraries used by an app so that they can be relocated into the final packaged binary. Building a `manylinux` binary wheel involves a tool named `auditwheel` that performs a very similar process. Unfortunately, processing a binary with Linuxdeploy after it has been processed by `auditwheel` can result in a binary library that cannot be loaded at runtime.
220
221 This is particularly common when a module installed as a binary wheel has a dependency on external libraries. For example, Pillow is a Python library that contains a binary submodule; that submodule uses `libpng`, `libtiff`, and other system libraries for image manipulation. If you install Pillow from a `manylinux` wheel, you may see an error similar to the following at runtime:
222
223 ```console
224 Traceback (most recent call last):
225 File "/tmp/.mount_TestbewwDi98/usr/app/testbed/app.py", line 54, in main
226 test()
227 File "/tmp/.mount_TestbewwDi98/usr/app/testbed/linux.py", line 94, in test_pillow
228 from PIL import Image
229 File "/tmp/.mount_TestbewwDi98/usr/app_packages/PIL/Image.py", line 132, in <module>
230 from . import _imaging as core
231 ImportError: libtiff-d0580107.so.5.7.0: ELF load command address/offset not properly aligned
232 ```
233
234 This indicates that one of the libraries that has been included in the AppImage has become corrupted as a result of double processing.
235
236 The solution is to ask Briefcase to install the affected library from source. This can be done by adding a `"--no-binary"` entry to the [`requires`][] declaration for your app. For example, if your app includes Pillow as a requirement:
237
238 ```python
239 requires = ["pillow==9.1.0"]
240 ```
241
242 You can force Briefcase to install Pillow from source by adding:
243
244 ```python
245 requires = [
246 "pillow==9.1.0",
247 "--no-binary", "pillow",
248 ]
249 ```
250
251 Since the library will be installed from source, you also need to add any system requirements that are needed to compile the binary library. For example, Pillow requires the development libraries for the various image formats that it uses:
252
253 ```python
254 system_requires = [
255 ... other system requirements ...
256 "libjpeg-dev",
257 "libpng-dev",
258 "libtiff-dev",
259 ]
260 ```
261
262 If you are missing a system requirement, the call to `briefcase build` will fail with an error:
263
264 ```console
265 error: subprocess-exited-with-error
266
267 × pip subprocess to install build dependencies did not run successfully.
268 │ exit code: 1
269 ╰─> See above for output.
270
271 note: This error originates from a subprocess, and is likely not a problem with pip.
272 >>> Return code: 1
273
274 Unable to install requirements. This may be because one of your
275 requirements is invalid, or because pip was unable to connect
276 to the PyPI server.
277 ```
278
279 You must add a separate `--no-binary` option for every binary library you want to install from source. For example, if your app also includes the `cryptography` library, and you want to install that library from source, you would add:
280
281 ```python
282 requires = [
283 "pillow==9.1.0",
284 "cryptography==37.0.2",
285 "--no-binary", "pillow",
286 "--no-binary", "cryptography",
287 ]
288 ```
289
290 If you want to force *all* packages to be installed from source, you can add a single `:all` declaration:
291
292 ```python
293 requires = [
294 "pillow==9.1.0",
295 "cryptography==37.0.2",
296 "--no-binary", ":all:",
297 ]
298 ```
299
300 The `--no-binary` declaration doesn't need to be added to the same [`requires`][] declaration that defines the requirement. For example, if you have a library that is used on all platforms, the declaration will probably be in the top-level [`requires`][], not the platform-specific [`requires`][]. If you add `--no-binary` in the top-level requires, the use of a binary wheel would be prevented on *all* platforms. To avoid this, you can add the requirement in the top-level requires, but add the `--no-binary` declaration to the Linux-specific requirements:
301
302 ```python
303 [tool.briefcase.app.helloworld]
304 formal_name = "Hello World"
305 ...
306 requires = [
307 "pillow",
308 ]
309
310 [tool.briefcase.app.helloworld.linux]
311 requires = [
312 "--no-binary", "pillow"
313 ]
314 ```