cancel
Showing results for 
Search instead for 
Did you mean: 

Can I use pyinstaller on Ubuntu to bundle Python code into an executable file and run it on STM32?

Ken_102633
Associate II

 

Hello,

I am a newcomer to embedded systems. I have a STM32MP157D-DK1 and I'm planning to develop some python applications to run on the A7 processor. I am encountering some issues.

1. I created a simple web application using Python on Ubuntu. (python module: Flask)
2. I confirmed that it can be executed successfully.
3. I bundled it into a single executable file using pyinstaller (PC $> pyinstaller app.py --onefile).
4. I verified that the executable file can be used properly.
5. I transferred the file to an STM32 (starter kit).
6. When I tried to execute the file, an error occurred.
Error Message:
./app: line 1: syntax error: unexpected ")"

Other experiments:
I try to execute python source code directly on STM32, there is no problem.
I try to bundle python code into a single executable on STM32, but can't install pyinstaller. (pip3 install pyinstaller)

Thanks for your support,
Ken.

10 REPLIES 10
Jean-Marc B
ST Employee

Hi @Ken_102633 

The app you created with pyinstaller from your PC running ubuntu is compiled for an architecture compatible with your PC (most probably x86_64). However, STM32MP15 boards rely on a ARM architecture hence can't run x86_64 app. That explains the error you got in your 6th step.

Then, installing pyinstaller from pip3 shows errors as some build dependencies are not available such as a gcc toolchain. To bypass these dependencies, you need to build your own distribution and setup your own repository (please refer to https://wiki.st.com/stm32mpu/wiki/Package_repository_for_OpenSTLinux_distribution#How_to_activate_a_local_package_repository )

Once your repository is activated, install the package group core-buildessential:

 

root@stm32mp1:~# apt-get update
root@stm32mp1:~# apt-get install packagegroup-core-buildessential
# EDITED SECTION BELOW
root@stm32mp1:~# apt-get install ldd

 

 You can now install pyinstaller with the following command:

 

root@stm32mp1:~# env PYI_STATIC_ZLIB=1 pip3 install pyinstaller

 

Then try to build your app.

Best regards,

--JM

Thank you so much @Jean-Marc B , the steps listed here helped to install and work with pyinstaller on stm device!

Firstly I builded the latest distribution package to kit. then-

I have done steps according to this link (https://wiki.st.com/stm32mpu/wiki/Package_repository_for_OpenSTLinux_distribution#How_to_activate_a_local_package_repository)

1.

cd [your STM32MP2 Distribution path]/build-openstlinuxweston-stm32mp15-disco
bitbake package-index

2.

cd [your STM32MP2 Distribution path]/build-openstlinuxweston-stm32mp15-disco/tmp-glibc/deploy/deb
python3 -m http.server &

In this path which is provided i have seen that in my distribution build only 3 of files are their and they are all, cortexa7t2hf-neon-vfpv4 and stm32mp15_disco.

3.on board(kit)

echo "deb [trusted=yes] http://<IP>:8000/stm32mp1 /" > /etc/apt/sources.list.d/my_custom.list
echo "deb [trusted=yes] http://<IP>:8000/all /" >> /etc/apt/sources.list.d/my_custom.list
echo "deb [trusted=yes] http://<IP>:8000/cortexa7t2hf-neon-vfpv4 /" >> /etc/apt/sources.list.d/my_custom.list
echo "deb [trusted=yes] http://<IP>:8000/cortexa7hf-neon-vfpv4 /"  >> /etc/apt/sources.list.d/my_custom.list

in this i have added ip of host pc.

but when i tried the deb things for the board it was not able to fetch 

Mohanv_1-1732711465510.png

Then as you mentioned in this thread to do:

root@stm32mp1:~# apt-get update
root@stm32mp1:~# apt-get install packagegroup-core-buildessential
# EDITED SECTION BELOW
root@stm32mp1:~# apt-get install ldd

after that it is not able to install the core build essetial 
it shows the error that it is not able to locate the build essetial 

ldd where installed .

atlast i was not able to install pyinstaller 

 

Hii @Jean-Marc B 

Please help me to resolve the issue .
As i mentioned in my above post.

Your help would be great.

Hi @Mohanv 

From your linux PC, check the packagegroup-core-buildessential package is available in your local deb directory:

[your STM32MP2 Distribution path]/build-openstlinuxweston-stm32mp15-disco/tmp-glibc/deploy/deb

by typing the following command:

$ find . -name "packagegroup-core-buildessential_*.deb" -print

 If the package is missing, you need to build it with the command and redo the package indexes:

$ bitbake packagegroup-core-buildessential
$ bitbake package-index

 

From your board, update your APT configuration and check the package is available:

root@stm32mp1:~# apt-get update
root@stm32mp1:~# apt-cache policy packagegroup-core-buildessential
root@stm32mp1:~# apt-get update
root@stm32mp1:~# apt-cache policy packagegroup-core-buildessential

 If yes, then perform the installation:

root@stm32mp1:~# apt-get install packagegroup-core-buildessential

Best regards,

--JM

 

Hii @Jean-Marc B 
Thank you for the response .


I have done the steps as you suggested, I was able build and fetch the packagegroup-core-buildessential for my board .

but while getting the apt update 

I got this error

Mohanv_0-1732804871893.png

so when I viewed in my host pc for deb files in the build path 

Mohanv_1-1732805050094.png

 so i changed the filename for getting from the server of host pc

echo "deb [trusted=yes] http://<IP>:8000/stm32mp15_disco /" > /etc/apt/sources.list.d/my_custom.list

 and I also saw that the cortexa7hf-neon-vfpv4 is missing in my built 

Still I went ahead try to install pyinstaller but I ran into this error 

Mohanv_2-1732805414569.png


 

Hi @Mohanv 

The error says the libz library is missing.

Try to build it if not present in your repo (bitbake zlib1) or install it with apt-get install zlib1

Best regards,

--JM

Hi @Jean-Marc B 
and thank you for your quick response.

I was not able to build the zlib1 and was also not able to install it. with error

Mohanv_0-1732888733943.png


and my main concern is to install pyinstaller. 

so is this zlib is needed to do that .

I have doubt when you said that to rearrange the index in above suggestion , so should we not need to flash it to the kit

Guide me step by step to get proper files so i can install pyinstaller properly and as i mentioned above message you can see that it have error with pyproject.toml time.

Hi @Mohanv 

The bitbake error message shows the right recipe to be called: zlib.

So, you need to build zlib then update your package index. That would give:

$ bitbake zlib
$ bitbake package-index

Then refresh your APT configuration and install the zlib package from your ST board:

# apt-get update
# apt-get install zlib

Best regards,

--JM