@@ -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,37 @@ 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."""
614
- try :
615
- import certifi
616
- except ImportError :
617
- print ("Info: certifi not available; skipping CA environment setup." )
618
- return
619
-
620
- cert_path = certifi .where ()
612
+ def _setup_certifi_env (env , python_exe = None ):
613
+ """
614
+ Setup certifi environment variables with priority from the given python_exe virtual environment.
615
+ If python_exe is provided, runs a subprocess to extract certifi path from that env to guarantee penv usage.
616
+ Falls back to importing certifi from current environment on failure.
617
+ """
618
+ cert_path = None
619
+ if python_exe :
620
+ try :
621
+ # Run python executable from penv to get certifi path
622
+ out = subprocess .check_output (
623
+ [python_exe , "-c" , "import certifi; print(certifi.where())" ],
624
+ text = True ,
625
+ timeout = 5
626
+ )
627
+ cert_path = out .strip ()
628
+ except Exception :
629
+ cert_path = None
630
+ if not cert_path :
631
+ try :
632
+ import certifi
633
+ cert_path = certifi .where ()
634
+ except Exception :
635
+ print ("Info: certifi not available; skipping CA environment setup." )
636
+ return
637
+ # Set environment variables for certificate bundles
621
638
os .environ ["CERTIFI_PATH" ] = cert_path
622
639
os .environ ["SSL_CERT_FILE" ] = cert_path
623
640
os .environ ["REQUESTS_CA_BUNDLE" ] = cert_path
624
641
os .environ ["CURL_CA_BUNDLE" ] = cert_path
625
-
642
+
626
643
# Also propagate to SCons environment if available
627
644
if env is not None :
628
645
env_vars = dict (env .get ("ENV" , {}))
0 commit comments