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

Importing python modules - advice wanted

asked 2018-11-07 14:58:50 +0300

DaveRo gravatar image

I succeeded in getting the app I referred to in this question working. My solution involves a module called pexpect. I simply put pexpect in a directory in /home/nemo (this is a private app).

This works when I run it from the SDK and also when I run it with
/usr/bin/sailfish-qml xmms2_control
but fails when I tap the desktop icon:
ImportError: No module named 'pexpect'

I think what I could do is put this module in the project tree somewhere and modify PYTHONPATH (?) in the app before the import. Before I try that, though, is there a generally accepted location and method of doing this?

edit retag flag offensive close delete

1 Answer

Sort by » oldest newest most voted
1

answered 2018-11-07 15:16:52 +0300

martyone gravatar image

updated 2018-11-07 20:46:53 +0300

The module can be installed under /usr/share/<your-app-name>/- see https://harbour.jolla.com/faq#2.1.0

Module search path can be set e.g. with:

import sys
sys.path.append('/usr/share/<your-app-name>')
edit flag offensive delete publish link more

Comments

Does not work. Or there's more to it.

[root@Sailfish nemo]# mv pexpect /usr/share/xmms2_control
[root@Sailfish nemo]# mv ptyprocess /usr/share/xmms2_control

$ ls -al /usr/share/xmms2_control/
total 24
drwxr-xr-x   6 root root 4096 Nov  7 14:48 .
drwxr-xr-x 174 root root 4096 Nov  7 12:20 ..
drwxrwxr-x   3 nemo nemo 4096 Nov  3 16:33 pexpect
drwxrwxr-x   3 nemo nemo 4096 Nov  3 16:41 ptyprocess
drwxr-xr-x   4 root root 4096 Nov  7 12:20 qml
drwxr-xr-x   2 root root 4096 Nov  7 12:20 translations

I now get the import error even using
/usr/bin/sailfish-qml xmms2_control

DaveRo ( 2018-11-07 17:08:42 +0300 )edit

Fixed it by adding

import sys
sys.path.append('/usr/share/xmms2_control')

If this were not a private app it would be better to have the files within the rpm.

DaveRo ( 2018-11-07 18:30:44 +0300 )edit

I was answering your question "is there a generally accepted location?". This is a location where you can install any files private to your app - like 3rdparty libraries. The type of the content does not matter. You can include the files within the RPM. You have to setup search paths etc. yourself - as you did :)

martyone ( 2018-11-07 20:45:08 +0300 )edit

Thanks. I meant specifically python modules, but I didn't make that clear.

DaveRo ( 2018-11-07 21:32:24 +0300 )edit
Login/Signup to Answer

Stats

Asked: 2018-11-07 14:58:50 +0300

Seen: 393 times

Last updated: Nov 07 '18