Skip to content

Commit f7d4413

Browse files
authored
Merge pull request RustPython#5036 from dannasman/path_error_message
Path error message
2 parents d5a6284 + 5f6059e commit f7d4413

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

vm/src/vm/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,19 @@ impl VirtualMachine {
223223
#[cfg(feature = "encodings")]
224224
fn import_encodings(&mut self) -> PyResult<()> {
225225
self.import("encodings", None, 0).map_err(|import_err| {
226-
let err = self.new_runtime_error(
227-
"Could not import encodings. Is your RUSTPYTHONPATH set? If you don't have \
226+
let msg = if !self.state.settings.path_list.iter().any(|s| s == "PYTHONPATH" || s == "RUSTPYTHONPATH"){
227+
"Could not import encodings. Is your RUSTPYTHONPATH or PYTHONPATH set? If you don't have \
228228
access to a consistent external environment (e.g. if you're embedding \
229229
rustpython in another application), try enabling the freeze-stdlib feature"
230-
.to_owned(),
231-
);
230+
.to_owned()
231+
} else {
232+
"Could not import encodings. Try adding your path to Setting struct's path_list field. If you don't have \
233+
access to a consistent external environment (e.g. if you're embedding \
234+
rustpython in another application), try enabling the freeze-stdlib feature"
235+
.to_owned()
236+
};
237+
238+
let err = self.new_runtime_error(msg);
232239
err.set_cause(Some(import_err));
233240
err
234241
})?;

0 commit comments

Comments
 (0)