PyOxidizer icon indicating copy to clipboard operation
PyOxidizer copied to clipboard

Avoid conflict in program arguments

Open katetsu opened this issue 3 years ago • 5 comments

I am working with pyembed to embed a python kernel and using default python config for the kernel. however, i can see that there is an issue when im trying to pass args to my program to start. error is:

Try `python -h' for more information.
Error: during initializing Python core: could not format PyStatus

any ideas?

Also, when running cargo test -- --nocapture, im getting:

unknown option --nocapture
Dynamic("during initializing Python core: could not format PyStatus")'

without -- --nocapture, my tests run fine.

katetsu avatar Nov 15 '21 15:11 katetsu

That during initializing Python core: could not format PyStatus error occurs when Py_InitializeFromConfig() errors and the resulting PyStatus doesn't have an annotated function name or message. That's a bit weird, as I thought CPython would always set these fields to help debugging.

Do you know what Python interpreter/library you are linking against to reproduce this?

indygreg avatar Nov 17 '21 02:11 indygreg

Here is a minimal reproducible example:

// lib.rs
include!("../kernel_artifacts/default_python_config.rs");
use std::io::{Error, ErrorKind};
use pyembed::MainPythonInterpreter;


pub struct PythonEnv <'a, 'b>{
    interpreter: Option<MainPythonInterpreter<'a, 'b>>,
}
impl <'a, 'b>PythonEnv <'a, 'b>{
    pub fn new() -> Result<Self, Error> {
        let config = default_python_config();
        let interpreter = MainPythonInterpreter::new(config).unwrap();
        Ok(PythonEnv { interpreter: Some(interpreter) })
    }
}

#[cfg(test)]
mod test {
    use super::*;

#[test]
fn test_foo(){
    let a = PythonEnv::new().unwrap();   
}

}

Run:

PYO3_CONFIG_FILE=./kernel_artifacts/pyo3-build-config-file.txt cargo test -- --nocapture

i have tested this with py38 and py39 both on mac and linux. - same error everywhere.

katetsu avatar Nov 17 '21 11:11 katetsu

any hope for this?

katetsu avatar Nov 22 '21 17:11 katetsu

You'd have to give me steps to reproduce, including how you generated the kernel_artifacts directory. Could you provide a Dockerfile or a shell script to run inside a base Docker image to run that can reproduce?

Do you have any PYTHON* environment variables that may be influencing behavior of the embedded interpreter?

indygreg avatar Nov 23 '21 01:11 indygreg

I can reproduce this with (PyOxy 0.2.0 x64 linux) with pyoxy run-python -- --version

It'll print the Python version then croak with:

error: Error {
    context: "initializing Python interpreter",
    source: Dynamic(
        "during initializing Python core: could not format PyStatus",
    ),
}

thejcannon avatar Dec 08 '22 15:12 thejcannon