Skip to content
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

pyoxidizer init-rust-project does not works as documented #335

Open
the-ica opened this issue Dec 5, 2020 · 3 comments · May be fixed by #717
Open

pyoxidizer init-rust-project does not works as documented #335

the-ica opened this issue Dec 5, 2020 · 3 comments · May be fixed by #717

Comments

@the-ica
Copy link

the-ica commented Dec 5, 2020

pyoxidizer init-rust-project pyapp

I then modified src/main.rs :

#![windows_subsystem = "console"]

use pyembed::MainPythonInterpreter;

// Include an auto-generated file containing the default
// pyembed::OxidizedPythonInterpreterConfig derived by the PyOxidizer
// configuration file.
//
// If you do not want to use PyOxidizer to generate this file, simply
// remove this line and instantiate your own instance of
// pyembed::OxidizedPythonInterpreterConfig.
include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS"));

fn main() {
    // The following code is in a block so the MainPythonInterpreter is destroyed in an
    // orderly manner, before process exit.
    let code = {
        // Load the default Python configuration as derived by the PyOxidizer config
        // file used at build time.
        let config = default_python_config();

        // Construct a new Python interpreter using that config, handling any errors
        // from construction.
        match MainPythonInterpreter::new(config) {
            Ok(mut interp) => {
                // And run it using the default run configuration as specified by the
                // configuration. If an uncaught Python exception is raised, handle it.
                // This includes the special SystemExit, which is a request to terminate the
                // process.
                // interp.run_as_main()
                let py = interp.acquire_gil().unwrap();
                match py.eval( "print('hello, world')", None, None) {
                    Ok(_) => println!("python code executed successfully"),
                    Err(e) => println!("python error: {:?}", e),
                }
                0
            }
            Err(msg) => {
                eprintln!("{}", msg);
                1
            }
        }
    };

    // And exit the process according to code execution results.
    std::process::exit(code);
}

but when running

pyoxidizer run

I get the same python REPL as without modification !

And also,

cargo run --features jemalloc build-mode-pyoxidizer-exe

fail with

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

That may be normal, but nothing tell me why in the doc.

I'm using ubuntu 20.04 and rust/cargo 1.47

@noahssarcastic
Copy link

I am also having this problem but I haven't changed the sample rust project except for enabling jemalloc in Cargo.toml.
Ubuntu 18.04.5
Rust 1.49.0
PyOxidizer 0.10.3

@Skehmatics
Copy link

Skehmatics commented Sep 15, 2023

What particularly bugs me about this is that the documentation mentions many times in relation to mixed python-rust projects to use pyoxidizer rather than cargo to build in order to perform many key steps you would otherwise need to glue together yourself, but doing so doesn't utilize any of your Rust code at all!

@dae
Copy link
Contributor

dae commented Sep 15, 2023

Here's how I work around it: #466

@Skehmatics Skehmatics linked a pull request Sep 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants