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

Python 3.6: SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported! (pyo3 v0.14.5) #1911

Closed
Congyuwang opened this issue Oct 13, 2021 · 7 comments

Comments

@Congyuwang
Copy link

🐛 Bug Reports

Building on python 3.6.15 fails to run on python 3.6.13. Below is the error message:

❯ python
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59) 
[GCC Clang 10.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import string_sum
>>> string_sum.sum_as_string(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

If I build the same project using python 3.6.13 on my laptop, it runs successfully.

🌍 Build Environment (Github Workflow)

  • OS: runs-on: macos-latest, Mac OS X 10.15.7 19H1417
  • python version: 3.6.15
  • python installation: actions/setup-python@v2, with: python-version: 3.6, architecture: x64
  • rust: stable-x86_64-apple-darwin unchanged - rustc 1.55.0 (c8dfcfe04 2021-09-06)
  • Your PyO3 version: pyo3 v0.14.5

Run Environment (My Laptop)

  • OS: Mac OS X 11.6
  • python version: 3.6.13
  • python installation: conda install python=3.6

💥 Reproducing

lib.rs

use pyo3::prelude::*;

/// Formats the sum of two numbers as string.
#[pyfunction]
fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
    Ok((a + b).to_string())
}

/// A Python module implemented in Rust. The name of this function must match
/// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
/// import the module.
#[pymodule]
fn string_sum(_py: Python, m: &PyModule) -> PyResult<()> {
    m.add_function(wrap_pyfunction!(sum_as_string, m)?)?;

    Ok(())
}

Cargo.toml

[package]
name = "string_sum"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib"]

[dependencies]
pyo3 = { version = "0.14.5", features = ["extension-module"] }

pyproject.toml

[project]
name = "congyu_pyo3_bug"
version = "0.0.1"

[build-system]
requires = ["maturin>=0.11,<0.12"]
build-backend = "maturin"

Installing package:

pip install congyu_pyo3_bug==0.0.1 -i https://test.pypi.org/simple

Reproduce bug:

❯ python
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59) 
[GCC Clang 10.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import string_sum
>>> string_sum.sum_as_string(1, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported!

The repository where I built this: https://github.com/Congyuwang/congyu_pyo3_debug

Built using GitHub workflow: https://github.com/Congyuwang/congyu_pyo3_debug/blob/master/.github/workflows/blank.yml

@Congyuwang Congyuwang changed the title Python 3.6: SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported! (latest PyO3) Python 3.6: SystemError: Bad call flags in PyCFunction_Call. METH_OLDARGS is no longer supported! (pyo3 v0.14.5) Oct 13, 2021
@davidhewitt
Copy link
Member

See milesgranger/cramjam#62 (comment). I suspect that your github build is somehow configuring for a newer version by accident.

@davidhewitt
Copy link
Member

In particular:

Python 3.6 and 3.7 are not supported on Apple Silicon Macs anyway so I've removed universal2 wheels from them.

Sounds like you should not be using --universal2 flag in your call to maturin-action. PyO3/maturin-action#13

@Congyuwang
Copy link
Author

However, if I build with --universal2 flag on Python 3.6.13 on my laptop, everything works just fine.

@messense
Copy link
Member

@Congyuwang See PyO3/maturin-action@3c86483

Please give it try with uses: messense/maturin-action@main

@Congyuwang
Copy link
Author

I changed to uses: messense/maturin-action@main.

The workflow still runs normally: Built wheel for CPython 3.6m to dist/congyu_pyo3_bug-0.0.2-cp36-cp36m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

Running actions/setup-python@v2, python version has not changed: Successfully setup CPython (3.6.15).

Installing from pip install congyu_pyo3_bug==0.0.2 -i https://test.pypi.org/simple this time actually runs normally:

❯ python                                                            
Python 3.6.13 |Anaconda, Inc.| (default, Feb 23 2021, 12:58:59) 
[GCC Clang 10.0.0 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import string_sum
>>> string_sum.sum_as_string(1, 2)
'3'

I don't quite understand why, though.

@messense
Copy link
Member

I think it's because pyo3 0.14 actually does use Python metadata from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib (which was specified by PYO3_CROSS_LIB_DIR env var in maturin-action) which wasn't used before.

@Congyuwang
Copy link
Author

This problem seems solved with latest maturin-action@v1

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

No branches or pull requests

3 participants