How to add/install pygame to Yocto project on Raspberry Pi 4? - python

How can you install pygame to your yocto project? Can only seem to find old solutions that doesn't seem to work. I mange to install python3 without any issues, but the meta-python layer doesn't contain pygame as standard. How can you create your own layer/recipe to get pygame?
Tried to create my own recipe from the script here
but when I use bitbake add-layer <PATH>
I get an error saying that:
Specified layer directory <PATH> doesn't contain a conf/layer.conf file
SUMMARY = "Python Game Development"
HOMEPAGE = "https://www.pygame.org"
AUTHOR = "A community project. <pygame#pygame.org>"
LICENSE = "LGPL-2.0"
LIC_FILES_CHKSUM = "file://setup.py;md5=59f9a291287e87473bbb98f2c9291c5c"
SRC_URI = "https://files.pythonhosted.org/packages/9a/50/67767e5586a45e7e7b02e6f0e07853f8fcb81b54c66db6278f1a1344491f/pygame-2.1.2.tar.gz"
SRC_URI[md5sum] = "8467a125e9075fa701f082806d228366"
SRC_URI[sha256sum] = "d6d0eca28f886f0477cd0721ac688189155a587f2bb8eae740e52ca56c3ad23c"
S = "${WORKDIR}/pygame-2.1.2"
RDEPENDS_${PN} = ""
inherit setuptools3
How my other files look.
local.conf:
MACHINE ??= "raspberrypi4-64"
RASPBERRYPI_DISPLAY = " 1"
IMAGE_INSTALL:append = " python3"
IMAGE_FSTYPES = "wic wic.bmap"
bblayers.conf:
<PATH>/poky/meta \
<PATH>/poky/meta-poky \
<PATH>/poky/meta-yocto-bsp \
<PATH>/meta-openembedded/meta-oe \
<PATH>/meta-openembedded/meta-python \
<PATH>/meta-raspberrypi \

Have you managed to add pygame to Yocto? I'm trying to achieve the same thing.
I've also tried generating a recipe with pipoe. (Without creating a custom layer. I've added the recipe to ../sources/poky/meta/recipes-devtools/python.) The recipe is parsed successfully, however the compilation fails.
This is my python3-pygame_2.1.3.dev8.bb:
SUMMARY = "Python Game Development"
HOMEPAGE = "https://www.pygame.org"
AUTHOR = "A community project. <pygame#pygame.org>"
LICENSE = "LGPL-2.0"
LIC_FILES_CHKSUM = "file://setup.py;md5=f28719c8b1d7e19071bd25e2f3a54c06"
SRC_URI = "https://files.pythonhosted.org/packages/f0/34/fc13b596b637cc59961ed606447a27a96d31bfda3ca965b73ebd16a02750/pygame-2.1.3.dev8.tar.gz"
SRC_URI[md5sum] = "6cf32b59a453b9824f421065a0205b52"
SRC_URI[sha256sum] = "94d98328e73d56be35cc3ae8e31f9d95fbce4f3dca6a74f05c58f4c5ef18c33d"
S = "${WORKDIR}/pygame-2.1.3.dev8"
RDEPENDS_${PN} = "libsdl2"
inherit setuptools3

The solution that worked for me:
Add meta-python and meta-netoworking via meta-openembedded.
In local.conf add IMAGE_INSTALL:append = " python3-pip".
While up and running use the command pip3 install pygame

Related

How to specify repository branch for poetry?

I have Project A with a pyproject file like this
[tool.poetry]
name = "projectA"
version = "2.0"
description = "Package gathering for project A"
repository = "https://git.saas.tech/project-a"
[tool.poetry.dependencies]
Package B = "1.0"
I want to test a feature. How can i tell poetry to look at a specific branch ?
Is this possible ?
repository = "https://git.saas.tech/project-a/my-feature"
I did this as described in the docs and it solved my problem...
Package B= { git = "git#git.saas.tech/project-a.git", branch = "myfeature" }

scons uninstall runs Substfile

I have created the SConstruct to install the systemd user services but when I try to scons uninstall the temporary services files are creates which should not happen.
import os
PATH_WD = os.path.abspath(os.curdir)
env = Environment(
SUBSTFILESUFFIX = '.service',
SUBST_DICT = { '{{PATH_ROOT}}' : os.path.dirname(PATH_WD) },
ENV = {
'DBUS_SESSION_BUS_ADDRESS' : os.environ['DBUS_SESSION_BUS_ADDRESS'],
'XDG_RUNTIME_DIR' : os.environ['XDG_RUNTIME_DIR']
}
)
INSTALLED = env.Install(
target = os.path.expanduser('~/.config/systemd/user/'),
source = [
env.Substfile('service1'),
env.Substfile('service2'),
]
)
env.AddPostAction(INSTALLED, env.Action('systemctl --user daemon-reload'))
Alias('install', INSTALLED)
NoClean(INSTALLED)
Command('uninstall', INSTALLED, Delete(INSTALLED))
Default('install')
Second try..
Here's a trivial example which should work for you..
env=Environment()
prog=env.Program('main.c')
Default(prog)
installed_prog = env.Install('install_dir', prog)
Alias('install', installed_prog)
NoClean(installed_prog)
# You don't have to specify targets to Alias.. so it won't
# try to build those before executing the Action
Alias('uninstall', action=Delete(installed_prog))
AlwaysBuild('uninstall')
SCons builder calls are statements of relationships between nodes. You've associated the target "uninstall" with the source INSTALLED by calling the Command builder. So in order to "build" this target, you need the source, and the source is the list of nodes returned by calling the Install builder. So the Install has to happen before the uninstall can take place. Is there a reason you don't want SCons' clean functionality to be used here? To see this, try: scons --tree=all,linedraw -n uninstall

Include python-dropbox in Yocto

My Python application uses Dropbox and I need to include this library in my Yocto image. I managed to generate a recipe for it with pipoe (pipoe -p dropbox). Here it is:
SUMMARY = "Official Dropbox API Client"
HOMEPAGE = "http://www.dropbox.com/developers"
AUTHOR = "Dropbox <dev-platform#dropbox.com>"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=ef3219362ea5e452a18031af12f35eb6"
SRC_URI = "https://files.pythonhosted.org/packages/85/33/bffd4a7596f3280f8bd2796b4f09c5c701b99d5c8e68715351cc2b3eeca8/dropbox-10.3.0.tar.gz"
SRC_URI[md5sum] = "f6d1a30af7e202237d660213d22e48a7"
SRC_URI[sha256sum] = "5f296f13ee7c358ab41779a73c4922ed81199447566c1a4c8fbf23dbcda25e20"
S = "${WORKDIR}/dropbox-10.3.0"
RDEPENDS_${PN} = "python-requests python-six "
inherit setuptools
When I run it, it says:
| ERROR: Do not try to fetch `pytest-runner' for building. Please add its native recipe to DEPENDS.
and then
| raise DistributionNotFound(req, requirers)
| pkg_resources.DistributionNotFound: The 'pytest-runner' distribution was not found and is required by the application
so I added the following line to the generated recipe:
DEPENDS = "python3-pytest-runner-native "
But I still get the same error. Any idea?
Probably an issue with inconsistent Python version.
You inherit setuptools which is for python2. The RDEPENDS are for python2 dependencies. But you add python3-pytest-runner-native in DEPENDS.
I'd suggest finding out which python version to use for this software and use the same for all RDEPENDS, inherited classes (setuptools3 for python3), and DEPENDS.

Calling gcloud from bazel genrule

I am having some issues getting gcloud to run in a Bazel genrule. Looks like python path related issues.
genrule(
name="foo",
outs=["bar"],
srcs=[":bar.enc"],
cmd="gcloud decrypt --location=global --keyring=foo --key=bar --plaintext-file $# --ciphertext-file $(location bar.enc)"
)
The exception is:
ImportError: No module named traceback
From:
try:
gcloud_main = _import_gcloud_main()
except Exception as err: # pylint: disable=broad-except
# We want to catch *everything* here to display a nice message to the user
# pylint:disable=g-import-not-at-top
import traceback
# We DON'T want to suggest `gcloud components reinstall` here (ex. as
# opposed to the similar message in gcloud_main.py), as we know that no
# commands will work.
sys.stderr.write(
('ERROR: gcloud failed to load: {0}\n{1}\n\n'
'This usually indicates corruption in your gcloud installation or '
'problems with your Python interpreter.\n\n'
'Please verify that the following is the path to a working Python 2.7 '
'executable:\n'
' {2}\n\n'
'If it is not, please set the CLOUDSDK_PYTHON environment variable to '
'point to a working Python 2.7 executable.\n\n'
'If you are still experiencing problems, please reinstall the Cloud '
'SDK using the instructions here:\n'
' https://cloud.google.com/sdk/\n').format(
err,
'\n'.join(traceback.format_exc().splitlines()[2::2]),
sys.executable))
sys.exit(1)
My questions are:
How do I best call gcloud from a genrule?
What are the parameters needed to specify the python path?
How is Bazel blocking this?
Update:
Able to get it to run by specifying the CLOUDSDK_PYTHON.
Indeed, bazel runs in a sandbox, hence gcloud cannot find its dependencies. Acutally, I'm surprised gcloud can be invoked at all.
To proceed, I would wrap gcloud in a bazel py_binary and refer it with tools attribute in the genrule. You also need to wrap it with location in the cmd. In the end, you will have
genrule(
name = "foo",
outs = ["bar"],
srcs = [":bar.enc"],
cmd = "$(location //third_party/google/gcloud) decrypt --location=global --keyring=foo --key=bar --plaintext-file $# --ciphertext-file $(location bar.enc)",
tools = ["//third_party/google/gcloud"],
)
And for that you define in third_party/google/gcloud/BUILD (or anywhere your want, I just used a path that makes sense to me)
py_binary(
name = "gcloud",
srcs = ["gcloud.py"],
main = "gcloud.py",
visibility = ["//visibility:public"],
deps = [
":gcloud_sdk",
],
)
py_library(
name = "gcloud_sdk",
srcs = glob(
["**/*.py"],
exclude = ["gcloud.py"],
# maybe exclude tests and unrelated code, too.
),
deps = [
# Whatever extra deps are needed by gcloud to compile
]
)
I had a similar issue, worked for me running this command:
export CLOUDSDK_PYTHON=/usr/bin/python
(this was answered above as an update but I felt to post the whole command for future people coming here)

How to use KDE Okular's document view widget in a Python Qt app?

I am writing a desktop application in Python (3.4) on Linux using Qt (4.8) and PyQt.
Is there a way to use/import Okular's pdf view functionality as a widget? If yes, how?
This works for me:
import sys
from PyKDE4.kdecore import ki18n, KAboutData, KCmdLineArgs
from PyKDE4.kdecore import KLibLoader as ll
from PyKDE4.kdeui import KApplication
import PyKDE4.kparts as kp
appName = "KApplication"
catalog = ""
programName = ki18n ("KApplication")
version = "1.0"
description = ki18n ("KApplication")
license = KAboutData.License_GPL
copyright = ki18n ("(c) 2007 John Doe")
text = ki18n ("none")
homePage = "www.johndoe.com"
bugEmail = "johndoe#nowhere.com "
aboutData = KAboutData(
appName, catalog, programName, version, description,
license, copyright, text, homePage, bugEmail
)
KCmdLineArgs.init(sys.argv, aboutData)
app = KApplication()
win = kp.KParts.MainWindow()
okupart = ll.self().factory('okularpart').create()
win.setCentralWidget(okupart.widget())
win.show()
app.exec_()
pykde could provide the required functionality. I have not figured out how, though.
Get the latest version of pykde:
git clone git://anongit.kde.org/pykde4
Documentation:
https://techbase.kde.org/Development/Languages/Python
http://api.kde.org/pykde-4.3-api/install.html
Building it required PyQt4 and CMAKE. Some linux distributions ship an outdated version of FindPyQt.py (causing an error along the lines of Python importerror : pyqtconfig). A functional one can be found here:
https://github.com/qgis/QGIS/blob/master/cmake/FindPyQt.py
Place it in /usr/share/kde4/apps/cmake/modules/
For compiling your UI files into Python code, use pykdeuic4 instead of pyuic4:
pykdeuic4 file.ui > file.py

Categories