-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can the interpreter be chosen at runtime? #174
Comments
I'm going to assume you're embedding Python rather than writing a library to be rust-cpython links against Python as a library in that case. I don't think Python installs its DLLs system-wide, so you probably have to include the requisite Python DLL(s) with your Rust project. |
Your assumption is correct. |
I've never compiled any Rust binaries with dynamic dependencies for Windows, but I think it's safe to assume that Rust+rust-cpython just relies on the OS's dynamic loader. For Windows, that means that any bundled DLLs will need to be in the same folder as the EXE. (eg.
That's determined by the Python import path ( Here's some Rust code which will show you the default value of use cpython::Python;
fn main() {
let gil = Python::acquire_gil();
let py = gil.python();
let sys = py.import("sys").expect("Cannot import sys");
let path: Vec<String> = sys
.get(py, "path").expect("Cannot get sys.path")
.extract(py).expect("Cannot extract sys.path value");
println!("{:?}", path);
} They resolved the potential cyclic dependency between the import path and the
As with (It'd make sense if relative paths are resolved relative to the EXE, rather than the current working directory, for consistency with how Another option you might find useful is to include some of your Python code inside the EXE. That'd be done by using |
You might be interested in https://pyoxidizer.readthedocs.io/en/stable/ for embedding a Python interpreter in Rust binaries. It aims to solve a lot of these hard packaging problems. You can also look at the source code for the |
Is it possible to specify the interpreter to use, i.e., its path, at runtime?
Something like:
The reason for this is if I'm distributing a rust & python app I want to include a python subdir and have rust use that python (with all the extra dependencies I need) rather than any that might happen to be on the system. And, of course, this means that my users don't need to have their own python (e.g., on windows).
The text was updated successfully, but these errors were encountered: