Explore the field guideDocumentationField guidesCommunitySearchStoreJournal

2024-09-05

Convert a Python application into a Linyaps package

Follow the ScreenPen example from a Python environment to a Linyaps package, with the contributor’s original screenshots.

Reprinted from the forum: [Technical Exchange] How to convert Python program into Linyaps package Author:HelloWorld!


Migrating simple python programs to Linyaps on deepin23

Take ScreenPen as an example

Run ScreenPen module on global system

python3 -m screenpen
image.png

Install dependent library pyqt5

pip3 install pyqt5
image.png

Install dependent library numpy

pip3 install numpy

image.png
Install dependent library matplotlib

pip3 install matplotlib

image.png
Run module

python3 -m screenpen
image.png

Running in a virtual environment

Create a virtual environment

mhc@mhc-PC:~/Documents/screenpen-master$ python3 -m venv screenpen-venv #创建虚拟环境screenpen-venv 
mhc@mhc-PC:~/Documents/screenpen-master$ cd screenpen-venv/
mhc@mhc-PC:~/Documents/screenpen-master/screenpen-venv$ ls
bin  include  lib  lib64  pyvenv.cfg
mhc@mhc-PC:~/Documents/screenpen-master/screenpen-venv$ cd bin/
mhc@mhc-PC:~/Documents/screenpen-master/screenpen-venv/bin$ source activate #激活虚拟环境
(screenpen-venv) mhc@mhc-PC:~/Documents/screenpen-master/screenpen-venv/bin$

After activating the virtual environment, the screenpen-venv/bin directory will be added to the PATH environment variable

image.png
Copy the screenpen module to the screenpen-venv/lib/python3.12/site-packages directory

image.png
image.png

Install dependent libraries numpy, matplotlib, numpy

pip3 install pyqt5 numpy matplotlib

An error occurred when running the module

image.png

Install setuptools package

pip3 install setuptools
(screenpen-venv) mhc@mhc-PC:~/Documents/screenpen-master/screenpen-venv/lib/python3.12/site-packages$ python3 -m screenpen #运行模块
image.png

Here you can see the directory where dependent libraries are installed in the virtual environment.

image.png

image.png
The globally installed module is in /home/mhc/.local/lib/python3.12/site-packages

image.png

So one way to package Linyaps is to package a virtual environment into the Linyaps container, and then use a script to start the program

Here comes the important point, how to package Linyaps?

1. First create such a directory

image.png

2. Put python3 in the files directory

image.png

It is recommended to use this python3.11 virtual environment. When I used the python3.12 version, problems with libc and libm occurred during the build.

image.png
Successfully built using python3.11
image.png
Several aspects of the linglong.yaml file worth paying attention to
image.png
Just write the command to install dependent libraries in build.
The most important point is that the screenpen module is not put into the container

image.png
Build again

image.png
It ran successfully, of course icons and desktop are indispensable.

image.png
image.png

After installation, double-click the icon to run
image.png

python and case file download

English edition: Linglong editorial · 18 October 2026. Original publication: 2024-09-05.