@@ -482,7 +482,7 @@ def _setup_python_environment_core(env, platform, platformio_dir, should_install
482
482
_install_esptool_from_tl_install (platform , penv_python , uv_executable )
483
483
484
484
# Setup certifi environment variables
485
- _setup_certifi_env (env )
485
+ _setup_certifi_env (env , penv_python )
486
486
487
487
return penv_python , esptool_binary_path
488
488
@@ -609,20 +609,29 @@ def _install_esptool_from_tl_install(platform, python_exe, uv_executable):
609
609
610
610
611
611
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
+ """
614
617
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 } " )
618
627
return
619
-
620
- cert_path = certifi . where ()
628
+
629
+ # Set environment variables for certificate bundles
621
630
os .environ ["CERTIFI_PATH" ] = cert_path
622
631
os .environ ["SSL_CERT_FILE" ] = cert_path
623
632
os .environ ["REQUESTS_CA_BUNDLE" ] = cert_path
624
633
os .environ ["CURL_CA_BUNDLE" ] = cert_path
625
-
634
+
626
635
# Also propagate to SCons environment if available
627
636
if env is not None :
628
637
env_vars = dict (env .get ("ENV" , {}))
0 commit comments