Post script Import('env') not working

It has been a while since using Platformio and projects that worked are failing. I have a post script to copy firmware to an ota update folder and VSCode was complaining about the print commands without brackets and I noticed it was set to my system Python 3.7.3 . I can correct the print problems but the first line Import(‘env’) does not work. Do I have to install a specific Platformio module into Python for this to work? Clicking on the python version text let me switch to ~.platformio\python27\python.exe interpreter, but it still will not Import.

What error does it throw? You’re not trying to execute this directly with a python interpeter yourself right, but let PIO execute it in terms of a extra_script directive?

I’m not at the running stage, it is VSCode that is complaining about the errors, can I assume it will run correctly? I am used to working in Python in PyCharm where errors are errors.

Import() is SCons’ way of importing variables (SConscript() · SCons/scons Wiki · GitHub, SCons 3.1.1). Maybe you have to execute in the right PyEnv (C:\Users\<user>\.platformio\penv)

OK I will blame that on VSCode auto complete or whatever. The code runs fine. did a build and the firmware was copied fine.

thanks for the super fast reply’s

It was the Python Linting extension it asked to install, that was throwing all the errors. disabled it and it is no longer bothered by the non Python code.

Just for completenes’ sake: The Import() (and Export()) functions are generated at runtime in the __init__.py of the Scons.Script file: Here

And Import() and Export() are implemented here: scons/SConscript.py at 82579b2d0705067c63d1e01a1188a3dfb2ef4d90 · SCons/scons · GitHub

So I’m sure a python linter has a hard time in picking that, since it’s a runtime-defined variable. I don’t now if there’s a nice IDE way to program SCons Scripts, but that error is definitely ignorable.

1 Like