@@ -482,7 +482,7 @@ def _setup_python_environment_core(env, platform, platformio_dir, should_install
482482 _install_esptool_from_tl_install (platform , penv_python , uv_executable )
483483
484484 # Setup certifi environment variables
485- _setup_certifi_env (env )
485+ _setup_certifi_env (env , penv_python )
486486
487487 return penv_python , esptool_binary_path
488488
@@ -609,20 +609,29 @@ def _install_esptool_from_tl_install(platform, python_exe, uv_executable):
609609
610610
611611
612- def _setup_certifi_env (env ):
613- """Setup certifi environment variables with optional SCons integration."""
612+ def _setup_certifi_env (env , python_exe = None ):
613+ """
614+ Setup certifi environment variables from the given python_exe virtual environment.
615+ Uses a subprocess call to extract certifi path from that environment to guarantee penv usage.
616+ """
614617 try :
615- import certifi
616- except ImportError :
617- print ("Info: certifi not available; skipping CA environment setup." )
618+ # Run python executable from penv to get certifi path
619+ out = subprocess .check_output (
620+ [python_exe , "-c" , "import certifi; print(certifi.where())" ],
621+ text = True ,
622+ timeout = 5
623+ )
624+ cert_path = out .strip ()
625+ except Exception as e :
626+ print (f"Error: Failed to obtain certifi path from the virtual environment: { e } " )
618627 return
619-
620- cert_path = certifi . where ()
628+
629+ # Set environment variables for certificate bundles
621630 os .environ ["CERTIFI_PATH" ] = cert_path
622631 os .environ ["SSL_CERT_FILE" ] = cert_path
623632 os .environ ["REQUESTS_CA_BUNDLE" ] = cert_path
624633 os .environ ["CURL_CA_BUNDLE" ] = cert_path
625-
634+
626635 # Also propagate to SCons environment if available
627636 if env is not None :
628637 env_vars = dict (env .get ("ENV" , {}))
0 commit comments