PyO3 / PyO3/pyo3

sys.argv support: Consider call PySys_SetArgv on python initialization.

Open
#1,241 5 comments 0 reactions 1 assignee View on GitHub

@davidhewitt is already working on this.

Since Oct 18, 2020.

needs-design
Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Currently if I use sys.argv in python code, it would complain: 'module' object has no attribute 'argv'
This is because python's argv is not initialized.

I hope PyO3 can provide an option to initialize argv in its initialization.

Repro Example

use pyo3::prelude::*;


fn main_(py: Python) -> PyResult<()> {
    let sys = py.import("sys")?;
    let argv: Vec<String> = sys.get("argv")?.extract()?;
    println!("{:?}", argv);
    Ok(())
}

fn main() -> Result<(), ()> {
    Python::with_gil(|py| {
        main_(py).map_err(|e| {
            e.print_and_set_sys_last_vars(py);
        })
    })
}

Output:

AttributeError: module 'sys' has no attribute 'argv'
Error: ()

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.