You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RUSTPYTHONPATH is not set when using Settings::default() without clap #4988
I've manually set the RUSTPYTHONPATH in the system environment variable, Rust sees the correct folder location prior to calling the
vm::Interpreter::without_stdlib(Default::default()).enter(|vm| { ..
and yet, the following error appears:
encodings initialization failed. Only utf-8 encoding will be supported.
ModuleNotFoundError: No module named 'encodings'
The above exception was the direct cause of the following exception:
RuntimeError: Could not import encodings. Is your RUSTPYTHONPATH set? If you don't have access to a consistent external environment (e.g. if you're embedding rustpython in another application), try enabling the freeze-stdlib feature
Expected
No message
Actual
encodings initialization failed. Only utf-8 encoding will be supported.
ModuleNotFoundError: No module named 'encodings'
The above exception was the direct cause of the following exception:
RuntimeError: Could not import encodings. Is your RUSTPYTHONPATH set? If you don't have access to a consistent external environment (e.g. if you're embedding rustpython in another application), try enabling the freeze-stdlib feature
changed the title [-]RUSTPYTHONPATH is set in WINDOWS to the correct path, but there's still an error about missing encodings.[/-][+]RUSTPYTHONPATH is not set when using `Settings::default()` without clap[/+]on May 24, 2023
Settings::default() still leaves path_list empty on purpose, so a process-level RUSTPYTHONPATH is not applied to an embedded Interpreter::without_stdlib. That is the intended embed API.
The two follow-ups listed on this issue are in tree:
Settings::with_path (crates/vm/src/vm/setting.rs)
encodings-import failure text now says when the env var is set but was not copied into Settings / PyConfig::paths::module_search_paths, and tells embedders to build a custom Settings
Activity
fanninpm commentedon May 23, 2023
Does the problem persist after running
cargo clean?euanmacinnes commentedon May 23, 2023
Yes, it does
euanmacinnes commentedon May 23, 2023
If it's helpful, the dependencies tree is:
rustpython = { git="https://github.com/RustPython/RustPython", features = ['jit']}
fanninpm commentedon May 23, 2023
You probably need to depend on the
rustpython-vmcrate.euanmacinnes commentedon May 23, 2023
Aren't the crates yanked? 3+ years old...
fanninpm commentedon May 23, 2023
Try this:
fanninpm commentedon May 23, 2023
@youknowone Does this have anything to do with the parser migration?
euanmacinnes commentedon May 24, 2023
fanninpm commentedon May 24, 2023
One last troubleshooting step: does the problem persist after deleting
Cargo.lock?youknowone commentedon May 24, 2023
@euanmacinnes Are you using rustpython as dependency of your project? or directly using RustPython repository?
youknowone commentedon May 24, 2023
I think using RustPython repository by that part. Then Cargo.lock will not help.
euanmacinnes commentedon May 24, 2023
youknowone commentedon May 24, 2023
Oh, wow. It was totally broken for
Setting::default().RUSTPYTOHNPATHis only loaded whenopts_with_clapis used.[-]RUSTPYTHONPATH is set in WINDOWS to the correct path, but there's still an error about missing encodings.[/-][+]RUSTPYTHONPATH is not set when using `Settings::default()` without clap[/+]youknowone commentedon May 24, 2023
Hmm.. the behavior seems reasonable. It doesn't automatically load PYTHONPATH when user doesn't want.
But the the message seems very confusing.
@euanmacinnes try this:
euanmacinnes commentedon May 29, 2023
Ok nice! That works! Thanks!
youknowone commentedon Jun 1, 2023
2 tasks are expected to resolve this problem.
settings.path_listand suggestRUSTPYTHONPATHas one of the way to set it when running interpreter binary.settings.path_listcontainsPYTHONPATHorRUSTPYTHONPATHand generate different message. (optional)fn with_path(self, path: ...) -> SelftoSettingsfor convenience method.Both tasks will be easy tasks.
hbina commentedon Feb 15, 2025
Is this still a problem?
fix: improve error message when RUSTPYTHONPATH not loaded in Settings
youknowone commentedon Oct 6, 2026
Settings::default()still leavespath_listempty on purpose, so a process-levelRUSTPYTHONPATHis not applied to an embeddedInterpreter::without_stdlib. That is the intended embed API.The two follow-ups listed on this issue are in tree:
Settings::with_path(crates/vm/src/vm/setting.rs)Settings/PyConfig::paths::module_search_paths, and tells embedders to build a customSettingsClosing as resolved.
— commented by Grok 4.6