cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
1,805 Views
Registered: ‎03-18-2019

petalinux python adding modules

Jump to solution

Hello,

I am building petalinux 2017.4 for z706 and trying to bring up a custom webserver.

I've already enabled python2.7 and python3 in petalinux-config -c rootfs.

Python native SimpleHTTPserver.py (2.7) and socket.server(3.5) both works fine.

python3-setuptools is enabled.

python3 venv works and I am able to create one --without-pip.

Now I want to add flask and some other python modules to venv and work with python like in a big machine, but there is no pip. 

 

How do I do that?

I've seen https://forums.xilinx.com/t5/Embedded-Linux/Add-python-or-any-rpm-on-Petalinux/m-p/716911

and https://www.xilinx.com/support/answers/67160.html

but will it work for python modules?

Is there a simpler way like placing .py files somewhere in petalinux folders or just copying a prepared venv to the board and activating it there?

 

Thank you.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Moderator
Moderator
1,773 Views
Registered: ‎04-24-2017

Re: petalinux python adding modules

Jump to solution

Hi @johnsmith120485 ,

First you need to find the relavent packages in https://layers.openembedded.org/layerindex/branch/morty/recipes/?q=python and then add in petalinuxbsp.conf file as shown below as all the python packages are not available in rootfs menu config.

IMAGE_INSTALL_append = " \
    python \
python-pip \ python3 \
python3-pip \ "

Note: Some python packages are available different meta layers and you can't use those packages if they are not part of your project meta-layers(refer <plnx-proj-root>/build/conf/bblayers.conf)

For example python-flask is part of meta-python(https://layers.openembedded.org/layerindex/branch/morty/recipes/?q=flask) and if you don't include this layer in your project then you can't using python-flask in IMAGE_INSTALL variable.

Thanks,
Sandeep
PetaLinux Yocto | Embedded SW Support

---------------------------------------------------------------------------
Don’t forget to Reply, Kudo, and Accept as Solution.
---------------------------------------------------------------------------

View solution in original post

3 Replies
Highlighted
Moderator
Moderator
1,774 Views
Registered: ‎04-24-2017

Re: petalinux python adding modules

Jump to solution

Hi @johnsmith120485 ,

First you need to find the relavent packages in https://layers.openembedded.org/layerindex/branch/morty/recipes/?q=python and then add in petalinuxbsp.conf file as shown below as all the python packages are not available in rootfs menu config.

IMAGE_INSTALL_append = " \
    python \
python-pip \ python3 \
python3-pip \ "

Note: Some python packages are available different meta layers and you can't use those packages if they are not part of your project meta-layers(refer <plnx-proj-root>/build/conf/bblayers.conf)

For example python-flask is part of meta-python(https://layers.openembedded.org/layerindex/branch/morty/recipes/?q=flask) and if you don't include this layer in your project then you can't using python-flask in IMAGE_INSTALL variable.

Thanks,
Sandeep
PetaLinux Yocto | Embedded SW Support

---------------------------------------------------------------------------
Don’t forget to Reply, Kudo, and Accept as Solution.
---------------------------------------------------------------------------

View solution in original post

Highlighted
1,755 Views
Registered: ‎03-18-2019

Re: petalinux python adding modules

Jump to solution

Will try this.

Thanks a lot, Sandeep!

 

UPDATE:

Following the above solution, I've edited file at petalinux/<project_root>/project-spec/meta-user/conf/petalinuxbsp.conf.

After building an image required packages appeared in /usr/lib/python3/site-packages.

To run code example like this

from flask import Flask
app = Flask(__name__)
        
@app.route("/")
def hello():
    return "Hello World!"
        
if __name__ == "__main__":
    app.run(host='0.0.0.0',port=80)

python3 hello.py

you have to enable python3-misc (for runpy.py) and python3-html from rootfs config.

 

As I understand, what happens here:

1) You have to cross-compile python to arm in any way you can, and install packages to the target.

2) Petalinux and Yocto (Open Embedded) projects provide cross-compilling tools and a huge base of recipes to make it easier. 

3) As there still may be custom python packages, that are not listed in database, you can write your own recipes to x-compile them.

4) Once x-compiled, a package seems to have an egg or wheel (python installation files). It becomes possible to create a folder on sd-card, containing x-compiled packages for specific projects, and installing them from there into venvs on board (this is what i've not tested so far).

 

Cheers

 

 

 

 

0 Kudos
Highlighted
Moderator
Moderator
1,742 Views
Registered: ‎09-12-2007

Re: petalinux python adding modules

Jump to solution