cancel
Showing results for 
Search instead for 
Did you mean: 

Linux CubeMX python is not working as pre/post code generation script

nobody
Associate II

What I have to do that I can directly call some python scripts as pre/post code generation step with CubeMX 6.14.1 under Linux?

Currently I can execute directly the python script on a Windows Machine, but on the Linux machine nothing happens. On Linux I can execute the scripts directly from command line without CubeMX and I can execute the scripts over a bash script which is calling the python script.

  • Do I need to configure anything additional?
  • Is there a possibility to select which python version is used?
  • Any other hint where my problem could be?

printscreen_UserAction_prePostCodeGeneration.png

Thanks in advance
nobody

 

16 REPLIES 16
KnarfB
Super User

does your script contain a proper shebang?

has it the executable flag set?

If so and it doesn't work, wrap it in a shell script.

hth

KnarfB

TDK
Super User

Does it work if you use "python ../../helloWorld.py"?

If you feel a post has answered your question, please click "Accept as Solution".

I tried different shebang's and I set also executable flag (See printscreens)
nobody_0-1746684023254.png

 

nobody_2-1746684054750.png

nobody_1-1746684029248.png

nobody_3-1746684087390.png

 

nobody
Associate II

Unfortunately it does not work with python before the path. Without python cubeMX does not complain, but it is not executed.

 

nobody_4-1746684165535.png

nobody_5-1746684171773.png

nobody_6-1746684364160.png

 

And what does "which python" on the command line return ?

nobody_0-1746692357783.png

 

This is just a test to check if python is there at all - although your comments implied it is.

However, I don't how Cube handles external tools.
One would expect to have options to set a path, or use the systems paths explicitely.

An example to the contrary would be e.g. the Pi Pico extension for VS Code (which runs under Linux as well).
VS Code will install the toolchain, cmake and ninja not in the system (nor use system-wide installed variants), but pull it's own versions into a ~/.vscode/ directory.

To see if it launches python at all: "python --version"

If that works then the file location is invalid, as the message states. You can use "pwd" or any other method to determine which path it runs these from.

If not, try the full path: "/usr/bin/python --version".

 

If you feel a post has answered your question, please click "Accept as Solution".

I think CubeMX, as Eclipse-based IDE, has a "terminal window" tab in it's GUI.
This terminal should use the same configuration as Cube, which are not the same ones' a standard terminal uses ( /etc/bash.bashrc and ~/<user>/.bashrc).

Try the "which python" (and "python --version") commands there.