# Hello World Example?

**URL:** <https://discourse.appimage.org/t/hello-world-example/161>\
**Category:** Creating AppImages\
**Created:** [March 16, 2017, 7:00am UTC](https://discourse.appimage.org/t/hello-world-example/161 "2017-03-16T07:00:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 16, 2017, 7:00am UTC](https://discourse.appimage.org/t/hello-world-example/161/1 "2017-03-16T07:00:51Z")

</div>

Dear all,

I am completely new to building packages.

I would like to create a universally installable package for two simple python scripts and include some .png icons.

Does someone have a simple Hello World example that I can use as a simple basis to create my package?

Yours,

Robert

---

<div class="post-metadata">

**Author:** ![MichaelTunnell](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/michaeltunnell/32/51_2.png) [@MichaelTunnell](https://discourse.appimage.org/u/MichaelTunnell)\
**Post date:** [March 16, 2017, 7:07am UTC](https://discourse.appimage.org/t/hello-world-example/161/2 "2017-03-16T07:07:12Z")

</div>

If all you want to do is install scripts and some icons then you can do that with a separate script. AppImages are great but might be a bit overkill for what it sounds like you are wanting to deploy.

---

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 16, 2017, 8:06am UTC](https://discourse.appimage.org/t/hello-world-example/161/3 "2017-03-16T08:06:04Z")

</div>

Dear Michael,

Thank you!

What do you mean by a separate script?

I still like the idea to package those simple scripts to make it easier for  
absolute Linux beginners to use them.

Yours,

Robert

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 16, 2017, 9:46am UTC](https://discourse.appimage.org/t/hello-world-example/161/4 "2017-03-16T09:46:07Z")

</div>

With AppImage you can bundle even more complex Python applications. For example, the Cura application is using Python and PyQt, and is completely self-standing.

The key is to bundle Python, the Python libraries, and your virtual Python environment inside the AppImage.

[https://github.com/probonopd/AppImageKit/wiki/Bundling-Python-apps](https://github.com/probonopd/AppImageKit/wiki/Bundling-Python-apps) should get you started. Please feel free to ask here if you get stuck; ideally with your sample application.

If you like, I can write a tiny “hello world” example bundling Python and a Python script inside an AppImage.

---

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 16, 2017, 5:00pm UTC](https://discourse.appimage.org/t/hello-world-example/161/5 "2017-03-16T17:00:44Z")

</div>

Dear @probono,

I appreciate your help!

I actually set up a Github repository that contains the scripts to give you  
a better idea of what I am trying to package:

> **[orschiro/dslli](https://github.com/orschiro/dslli)**
>
> dslli stands for Disable Standby Laptop Lid Indicator. - orschiro/dslli

Yours,

Robert

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 17, 2017, 1:36am UTC](https://discourse.appimage.org/t/hello-world-example/161/6 "2017-03-17T01:36:19Z")

</div>

Hello @orschiro, this `.yml` should do the trick:

```auto
app: dslli

ingredients:
  dist: trusty
  sources: 
    - deb http://archive.ubuntu.com/ubuntu/ trusty main universe
  packages:
    - python3-minimal
  script:
    - wget -c https://github.com/orschiro/dslli/archive/master.zip
    - unzip master.zip

script:
  - cat > dslli.desktop <<EOF
  - [Desktop Entry]
  - Type=Application
  - Name=dslli
  - Icon=dslli
  - Exec=dslli
  - Categories=Utility;
  - EOF
  - cp ../dslli-master/* usr/bin/
  - cp usr/bin/green.png usr/share/icons/hicolor/24x24/dslli.png
  - cp usr/share/icons/hicolor/24x24/dslli.png .
  - ( cd usr/bin/ ; ln -s toggle_lid.py dslli )
  - chmod a+x usr/bin/toggle_lid.py

```

To run this, put it into a file called `dslli.yml`, download the meta [Recipe](https://raw.githubusercontent.com/probonopd/AppImages/master/recipes/meta/Recipe), then run `bash -ex ./Recipe dslli.yml`.

The things in the `script:` section are mainly because your repository does not offer a desktop file and does not place files into the usual FHS-like `/usr/...` structure.

---

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 17, 2017, 7:37pm UTC](https://discourse.appimage.org/t/hello-world-example/161/7 "2017-03-17T19:37:35Z")

</div>

Dear @probono,

This is fantastic!

I am very appreciative of your help.

I added all this along with my attribution for your work to the Github repository. 🙂

Let me just ask you one question:

The final AppImage executes `toggle_lid.py`.

However, it does not yet include the other command `show_state.py`.

Is it better to include the latter into the already existing AppImage or should I create a second AppImage file for the other command?

Yours,

Robert

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 17, 2017, 7:50pm UTC](https://discourse.appimage.org/t/hello-world-example/161/8 "2017-03-17T19:50:11Z")

</div>

It depends: If `show_state.py` is called by `toggle_lid.py`, then you should put both into the same AppImage. If both are executed by the user manually, then each should be its own AppImage.

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 17, 2017, 7:51pm UTC](https://discourse.appimage.org/t/hello-world-example/161/9 "2017-03-17T19:51:39Z")

</div>

Oh, and please don’t store the AppImage in git, that’s what the GitHub Releases page is for 🙂

---

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 17, 2017, 9:39pm UTC](https://discourse.appimage.org/t/hello-world-example/161/10 "2017-03-17T21:39:12Z")

</div>

Dear @probono,

Thank you!

This is a great learning experience! 🙂

I added the .yml files to the repository and removed all the rest.

However, using this [1] .yml file, it finishes the building process but fails to run with the following error:

```auto
orschiro@x230:~/dslli/AppImageCompile/AppImage/showstate/out$ ./dslli-indicator-.glibc2.17-x86_64.AppImage 
/bin/bash: ../lib/x86_64-linux-gnu/libtinfo.so.5: no version information available (required by /bin/bash)
Traceback (most recent call last):
  File "/tmp/.mount_kD8ydv/usr/bin/dslli-indicator", line 7, in <module>
    gi.require_version('Gtk', '3.0')
  File "/tmp/.mount_kD8ydv/usr/lib/python3/dist-packages/gi/ __init__.py", line 83, in require_version
    (namespace, version))
ValueError: Namespace Gtk not available for version 3.0

```

Do you have any advice for me?

Yours,

Robert

[1] [https://github.com/orschiro/dslli/blob/master/show\_state.yml](https://github.com/orschiro/dslli/blob/master/show_state.yml)

---

<div class="post-metadata">

**Author:** ![probono](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/probono/32/81_2.png) [@probono](https://discourse.appimage.org/u/probono)\
**Post date:** [March 18, 2017, 9:04am UTC](https://discourse.appimage.org/t/hello-world-example/161/11 "2017-03-18T09:04:25Z")

</div>

Interesting problem here. There seems to be a library called `libgirepository-1.0.so.1` which contains a hardcoded path to `/usr/lib`. I suspect it is hardcoded to search for files like `/usr/lib/girepository-1.0/Gtk-3.0.typelib` in the system’s `/usr`, ignoring `$PYTHONPATH` and the like.

And indeed, the [documentation](https://pypi.python.org/pypi/pgi/) says

> Typelibs will be loaded from paths in the environment variable  
> GI\_TYPELIB\_PATH and /usr/lib/girepository-1.0/.

Hence, the application is trying to load the typelib file from the system (where it may or may not exist), failing.

We need to find a good way to make it load the file from inside the AppImage instead. As a temporary workaround, we can

- binary-patch the hardcoded `/usr` away, see [Use binpatch: true and add gir1.2-appindicator3-0.1 by probonopd · Pull Request #1 · orschiro/dslli · GitHub](https://github.com/orschiro/dslli/pull/1/files), or
- modify AppRun so that it sets the GI\_TYPELIB\_PATH environment variable

It would be much nicer if the library would be changed to make it relocateable, by using relative paths (relative to the `.so`) rather than the absolute path `/usr/lib/girepository-1.0/`. It would be great if you could submit an upstream feature request. Seems like others are having similar issues too: [Freezing a PyGI app · Issue #1966 · pyinstaller/pyinstaller · GitHub](https://github.com/pyinstaller/pyinstaller/issues/1966)

---

<div class="post-metadata">

**Author:** ![orschiro](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.appimage.org/orschiro/32/52_2.png) [@orschiro](https://discourse.appimage.org/u/orschiro)\
**Post date:** [March 18, 2017, 5:54pm UTC](https://discourse.appimage.org/t/hello-world-example/161/12 "2017-03-18T17:54:04Z")

</div>

Once again, my sincere thanks for all your help to build my first AppImage!

This forum made the difference for me.

In the future, I would recommend AppImage over Snap or Flatpak. 🙂
