Python issue - cannot find dotenv


So I have a script that is executed after compilation.
It was working find (copy bin to another folder) but recently I added module python-dotenv and problem started.
The same script works on Linux but does not work on MacOS.
Problem starts with:
from dotenv import dotenv_values
it cannot find the module.

But when I take this piece of code and use VSCode without Platformio there is no issue at all.
So I am suspecting that Platformio does not find the module.
But then how to install the python module that it will be visible inside VSCode AND Platformio?
Any hint would be appreciated.

I tried both: python from brew and even I installed official package - no difference: it works out of Platformio but it does not inside Platformio.

import sys
import os
import shutil
import subprocess
import ftplib
from dotenv import dotenv_values

and the error:

Building in release mode
ModuleNotFoundError: No module named 'dotenv':
  File "/Users/papio/.platformio/penv/lib/python3.11/site-packages/platformio/builder/", line 180:
    env.SConscript(env.GetExtraScripts("post"), exports="env")
  File "/Users/papio/.platformio/packages/tool-scons/scons-local-4.6.0/SCons/Script/", line 609:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/Users/papio/.platformio/packages/tool-scons/scons-local-4.6.0/SCons/Script/", line 279:
    exec(compile(scriptdata, scriptname, 'exec'), call_stack[-1].globals)
  File "/Users/papio/3-Programming/02-Platformio/00-production/01-arduino_ide/092-universal-mqtt-device/extra_scripts/", line 8:
    from dotenv import dotenv_values


Platformio v3.3.2
thank you

solved by applying this one:

I have a similar issue with tkinter on a Windows VS Code / PIO install. However, installing “tk” via pip is not sufficient.

I had to set the VSCode preference platformio-ide.useBuiltinPython to false and thereby make it use my global python installation, which had tkinter included (it is a python installer option that you actively had to uncheck during installing python). An alternative to all that could be to install ActiveState as a standalone Tkinter installation for windows, I guess? (see TkDocs Tutorial - Installing Tk )

1 Like