Pre and Pre/Post script Error

I have platformio installed running on a Rasbian Jessie Raspberry Pi v3 using the CLI.

I am following the instructions at:

Sitting in the directory of the application (e.g. /opt/piotest), this works fine:
pio run -t upload

Added an additional line to the existing platformio.ini:
platform = atmelavr
board = feather32u4
framework = arduino
extra_script = pre:/opt/piotest/

(also tried the extra_script value w/o pathing)

Created a simple python script that just prints a line (and works fine from command line) named

Getting this warning:
warning: Ignoring missing SConscript ‘’
File “/usr/local/lib/python2.7/dist-packages/platformio/builder/”, line 164, in

Nothing additional prints in output.

Checked file permissions and reset everything in /opt to my user, just in case something weird were causing the app to fail. No change.

Removed my original addition to platformio.ini. Copied/pasted your example into platformio.ini and from this thread:
Run script before/after image upload? - #3 by ivankravets

Similar error.

Any ideas on next steps?

Thanks, but yes I tried that prior (and just did again to be certain):
You’re up-to-date!
PlatformIO 3.4.0 is currently the newest version available.

Ah… I got it, pre:post prefixes were added in PlatformIO 3.4.1 which has not been released yet. See history:

You can switch to PlatformIO 3.4.1 dev version Redirecting...

Otherwise, please use documentation for PlatformIO 3.4.0 (stable)

Staying on current version for this test and following instructions linked at:

Running command:
pio run -t upload

Different error after successful upload:
[Fri Jul 14 14:55:58 2017] Processing pre_and_post_hooks (extra_script:
Error: Please specify platform for ‘pre_and_post_hooks’ environment

Seems like I’m missing a platform setting like:
platform = linux_arm

Just trying to figure out now where to put it in platformio.ini

You are going to process pre_and_post_hooks environment which is empty… Please specify here platform…

platform = linux_arm

Edited platformio.ini section to be:
platform = linux_arm
extra_script =

But had to alter first line of sample code for as it is invalid in Python 2.7.9:

Changed to a couple of variations:
import env
import PLATFORMIO.env

But still errors out as unknown module.
ImportError: No module named PLATFORMIO.env:

Feels like I’m close now.

Ran a pip freeze to get module names.

Did not work with trying the following as first line in
from platformio import env

How did you decide that this code is invalid?

Just trying it from the CLI it gives:
File “”, line 1, in
NameError: name ‘Import’ is not defined

Is env a part of the platformio package or something else?

This is a PlatformIO script and is not Python’s standalone. You should run it via pio run command.

Tried both. Same error regardless. <- not correct - see next post

Just trying the Python CLI to narrow it down to the syntax first of where the env module is coming from.

(Don’t you hate it when people jump ahead and think they know what you’re going to ask for next and you have to tell them to just stop jumping around and follow your guidance?)

Sorry, maybe I missed that and that line “works” when used within your framework but here’s what I get after putting that line back “as is” w/o modification:

[Fri Jul 14 16:00:12 2017] Processing pre_and_post_hooks (extra_script:; platform: linux_arm)
Verbose mode can be enabled via -v, --verbose option
Collected 3 compatible libraries
Looking for dependencies…
Project does not have dependencies
Current build targets [‘upload’]
***** Do not know how to make File target `upload’ (/opt/platformio/upload). Stop.**
========================== [ERROR] Took 1.79 seconds ==========================

What is your aim/task?

The board I am loading is in deep sleep mode w/ the USB disabled. Therefore, I have to time pressing the reset button on the board to coincide with platformio loading the board. I’d like to play an audio prompt (e.g. tone) right before the code starts loading to the board so that the timing is more accurate and less likely to be missed.

Pre is mostly what I am trying to get a handle on.

Do you understand what does it mean? You are going to build source code using native ARM compiler. Nevertheless, you said that you have a board connected to RPi. If you want to program it you SHOULD use environment which correspond to it. PlatformIO will autoamtically use own dependent toolchins to preapre firmware for your board.


Sorry, the configuration is:

  • Raspberry Pi 3 v2 (Raspbian Jessie - Minimal)
  • Adafruit Feather 32u4 (deep sleep)

Goal is to load updated software to the Adafruit Feather 32u4 from the RPi.

I am assuming that the platform value should linux_arm for the Pi vs. something else for the Adafruit Feather 32u4. Is that incorrect? Perhaps:
platform=Atmel AVR

See PlatformIO Registry

platform = atmelavr
framework = arduino
board = feather32u4
extra_script =