@@ -68,11 +68,49 @@ def add_to_pythonpath(path):
68
68
# Framework directory path
69
69
FRAMEWORK_DIR = platform .get_package_dir ("framework-arduinoespressif32" )
70
70
71
- # Add framework Python tools to path if available
72
- if FRAMEWORK_DIR :
73
- framework_python_path = os .path .join (FRAMEWORK_DIR , "tools" , "python" )
74
- if os .path .isdir (framework_python_path ):
75
- add_to_pythonpath (framework_python_path )
71
+ def setup_python_paths (env ):
72
+ """
73
+ Setup Python paths based on the actual Python executable being used.
74
+
75
+ Args:
76
+ env: SCons environment object
77
+ """
78
+ python_exe = env .subst ('$PYTHONEXE' )
79
+ if not python_exe or not os .path .isfile (python_exe ):
80
+ return
81
+
82
+ # Get the directory containing the Python executable
83
+ python_dir = os .path .dirname (python_exe )
84
+ add_to_pythonpath (python_dir )
85
+
86
+ # Try to find site-packages directory using the actual Python executable
87
+ try :
88
+ result = subprocess .run (
89
+ [python_exe , "-c" , "import site; print(site.getsitepackages()[0])" ],
90
+ capture_output = True ,
91
+ text = True ,
92
+ timeout = 5
93
+ )
94
+ if result .returncode == 0 :
95
+ site_packages = result .stdout .strip ()
96
+ if os .path .isdir (site_packages ):
97
+ add_to_pythonpath (site_packages )
98
+ except (subprocess .TimeoutExpired , FileNotFoundError , Exception ):
99
+ # Fallback: try common site-packages locations
100
+ possible_paths = [
101
+ os .path .join (python_dir , "Lib" , "site-packages" ), # Windows
102
+ os .path .join (python_dir , ".." , "lib" , f"python{ sys .version_info .major } .{ sys .version_info .minor } " , "site-packages" ), # Unix
103
+ ]
104
+
105
+ for path in possible_paths :
106
+ normalized_path = os .path .normpath (path )
107
+ if os .path .isdir (normalized_path ):
108
+ add_to_pythonpath (normalized_path )
109
+ break
110
+
111
+ # Setup Python paths based on the actual Python executable
112
+ setup_python_paths (env )
113
+
76
114
77
115
# Python dependencies required for the build process
78
116
python_deps = {
0 commit comments