We have moved to a new Sailfish OS Forum. Please start new discussions there.
4

How to run a Python app?

asked 2016-06-12 11:26:55 +0300

Ósanwe gravatar image

Hello!

I've cloned a sample python project and tried to build and run it. But sailfish-qml doesn't exist and I can't run the sample.

Previously I installed pyotherside-qml-plugin-python3-qt5 manually:

[root@Jolla nemo]# pkcon install pyotherside-qml-plugin-python3-qt5
Installing                                                                     
Waiting in queue                                                               
Starting                                                                        
Refreshing software list                                                       
Querying                                                                       
Resolving dependencies                                                         
Installing packages                                                            
Installing                                                                     
Waiting in queue                                                               
Waiting for authentication                                                     
Waiting in queue                                                               
Starting                                                                        
Refreshing software list                                                       
Querying                                                                       
Resolving dependencies                                                         
Installing packages                                                            
Downloading packages                                                           
Installing packages

Also I tried to run sample via terminal:

[root@Jolla nemo]# sailfish-qml pythonsample
bash: sailfish-qml: command not found

and install sailfish-qml

[root@Jolla nemo]# pkcon install sailfish-qml
Command failed: This tool could not find any available package: could not find sailfish-qml

How to build and run python apps correct?

Thanks in advance!

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
3

answered 2016-06-12 11:39:25 +0300

updated 2016-06-12 11:44:47 +0300

The example project does not work correctly, I found the way to use pyotherside in Sailfish QML. This took me several days until I fully understand why...

Warning: only Python 3 is supported! I never found a way to get my code running on Python 2...

First in your QML you import this:

import io.thp.pyotherside 1.3

They use 1.4 but that's not allowed in Harbour!

Then you can add the 'Python {}' to your QML:

Python 
{
    id: python

    Component.onCompleted: 
        {
        // Import the pad where you Python file is stored. In this case: /qml/pages
        addImportPath(Qt.resolvedUrl('.')); 

        // Import the module, the name = name of your Python script.
        importModule('pythonModule', function () {});

        // Receive here data from Python by using: pyotherside.send('receiver', data)
        setHandler('receiver', function(data) {
            // Do some stuff here with the data and QML.
        });
    }

    onError: 
    {
        // when an exception is raised, this error handler will be called
        console.log('python error: ' + traceback);
    }

    onReceived: 
    {
        // All the stuff you send, not assigned to a 'setHandler', will be shown here:
        console.log('got message from python: ' + data);
    }
}

If you want to use pyotherside in your project make sure you add it to your .yaml file as a dependency under 'Requires':

Requires:
- sailfishsilica-qt5 >= 0.10.9 
- pyotherside-qml-plugin-python3-qt5 >= 1.3.0

I never run it from the terminal, I deploy it with the SDK as an RPM package. In this case your app shows up as a normal app in the app grid and is started automatically after deploying.

edit flag offensive delete publish link more

Comments

Thanks! I edited the project but the problem is same. I found that libsailfishapp-launcher should be in Requires section. I added this line and received follow error: Error: File './oss/armv7hl/libsailfishapp-launcher-1.0.10-10.7.1.jolla.armv7hl.rpm' not found on medium 'https://releases.jolla.com/releases/2.0.1.11/jolla/armv7hl/'. When I tried to install this package via pkcon manually I got the same error.

Ósanwe ( 2016-06-12 12:05:47 +0300 )edit

I never had that error before, Sailfinder (in the Jolla Store) uses heavily Python and I only added one line to Requires.

Dylan Van Assche ( 2016-06-12 12:11:17 +0300 )edit
2

do pkcon refresh before manipulating with repos

coderus ( 2016-06-12 12:26:09 +0300 )edit

@coderus: It helped. Thanks!

Ósanwe ( 2016-06-12 12:34:07 +0300 )edit
Login/Signup to Answer

Question tools

Follow
3 followers

Stats

Asked: 2016-06-12 11:26:55 +0300

Seen: 1,504 times

Last updated: Jun 12 '16