@@ -113,18 +113,13 @@ pub fn init_stdlib(vm: &mut VirtualMachine) {
113113/// Setup frozen standard library (compiled into the binary)
114114#[ cfg( all( feature = "stdlib" , feature = "freeze-stdlib" ) ) ]
115115fn setup_frozen_stdlib ( vm : & mut VirtualMachine ) {
116+ use rustpython_vm:: common:: rc:: PyRc ;
117+
116118 vm. add_frozen ( rustpython_pylib:: FROZEN_STDLIB ) ;
117119
118- // FIXME: Remove this hack once sys._stdlib_dir is properly implemented
119- // or _frozen_importlib doesn't depend on it anymore.
120- assert ! ( vm. sys_module. get_attr( "_stdlib_dir" , vm) . is_err( ) ) ;
121- vm. sys_module
122- . set_attr (
123- "_stdlib_dir" ,
124- vm. new_pyobj ( rustpython_pylib:: LIB_PATH . to_owned ( ) ) ,
125- vm,
126- )
127- . unwrap ( ) ;
120+ // Set stdlib_dir to the frozen stdlib path
121+ let state = PyRc :: get_mut ( & mut vm. state ) . unwrap ( ) ;
122+ state. config . paths . stdlib_dir = Some ( rustpython_pylib:: LIB_PATH . to_owned ( ) ) ;
128123}
129124
130125/// Setup dynamic standard library loading from filesystem
@@ -135,6 +130,11 @@ fn setup_dynamic_stdlib(vm: &mut VirtualMachine) {
135130 let state = PyRc :: get_mut ( & mut vm. state ) . unwrap ( ) ;
136131 let paths = collect_stdlib_paths ( ) ;
137132
133+ // Set stdlib_dir to the first stdlib path if available
134+ if let Some ( first_path) = paths. first ( ) {
135+ state. config . paths . stdlib_dir = Some ( first_path. clone ( ) ) ;
136+ }
137+
138138 // Insert at the beginning so stdlib comes before user paths
139139 for path in paths. into_iter ( ) . rev ( ) {
140140 state. config . paths . module_search_paths . insert ( 0 , path) ;
0 commit comments