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

Importing zeep package panics with error: PyErr { type: 0x10f60b2c0 } #1273

Closed
fusillicode opened this issue Nov 12, 2020 · 6 comments
Closed

Comments

@fusillicode
Copy link

fusillicode commented Nov 12, 2020

🐛 Bug Reports

🌍 Environment

  • Your operating system and version: macOS Catalina Version 10.15.7 (19H2)
  • Your python version: 3.8.0
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: I installed it with asdf-python and tried both with and without Poetry venv
  • Your Rust version (rustc --version): rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
  • Your PyO3 version: 0.12.3
  • Have you tried using latest PyO3 master (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: yes and I got the same error

💥 Reproducing

A fresh Cargo binary project:

Cargo.toml

[package]
name = "dummy"
version = "0.1.0"
authors = ["fusillicode <me@gmail.com>"]
edition = "2018"

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

[dependencies]
pyo3 = "0.12.3"

src/main.rs

use pyo3::Python;
use pyo3::types::PyModule;

fn main() {
    let gil = Python::acquire_gil();
    let py = gil.python();

    let _mod = PyModule::import(py, "zeep").unwrap();
}

Output:

 cargo run -p dummy
    Blocking waiting for file lock on build directory
   Compiling pyo3 v0.12.3
   Compiling dummy v0.1.0 (/Users/me/code/example/dummy)
    Finished dev [unoptimized + debuginfo] target(s) in 2m 07s
     Running `target/debug/dummy`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PyErr { type: 0x10f60b2c0 }', dummy/src/main.rs:8:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

No specific flags were used.
No problem were encountered when importing another library, lxml, a dependency of zeep.
However the error under discussion arose also while importing other apparently unrelated libraries, e.g. docxtpl.

For anything I remain obviously at your total disposal.

Thanks for all your incredible work 🙇

@davidhewitt
Copy link
Member

@fusillicode thanks for the report. I couldn't reproduce this on my local machine (Ubuntu 20.04, Python 3.9, latest zeep). I suspect environment misconfiguration, but hard to be sure without more diagnostics.

We just merged some improvements to pyo3 which should output more helping information on a panic. Can you please retry with the latest pyo3 master, which should give a more helpful error message?

Also, you could try replacing

let _mod = PyModule::import(py, "zeep").unwrap();

with

pyo3::py_run!(py, "import zeep");

Which will also print the python traceback, if needed.

@fusillicode
Copy link
Author

Thank you for the quick support and again for all your work 🙇

I've tried using pyo3::py_run!(py, "import zeep"); with the latest master version Compiling pyo3 v0.12.3 (https://github.com/PyO3/pyo3#aa30163e) but unfortunately I get this compilation error:

error: no rules expected the token `"import zeep"`
 --> negative_events/src/main.rs:8:23
  |
8 |     pyo3::py_run!(py, "import zeep");
  |                       ^^^^^^^^^^^^^ no rules expected this token in macro call

However with let _mod = PyModule::import(py, "zeep").unwrap(); I now get a more descriptive error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PyErr { type: <class 'ImportError'>, value: ImportError('dlopen(/Users/me/.asdf/installs/python/3.8.0/lib/python3.8/lib-dynload/_posixsubprocess.cpython-38-darwin.so, 2): Symbol not found: _PyOS_AfterFork_Child\n  Referenced from: /Users/me/.asdf/installs/python/3.8.0/lib/python3.8/lib-dynload/_posixsubprocess.cpython-38-darwin.so\n  Expected in: flat namespace\n in /Users/me/.asdf/installs/python/3.8.0/lib/python3.8/lib-dynload/_posixsubprocess.cpython-38-darwin.so'), traceback: Some(<traceback object at 0x10d87e180>) }', dummy/src/main.rs:9:45
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

If there is anything I can do to simplify the troubleshooting I remain at your total disposal.

Thanks again.

@davidhewitt
Copy link
Member

error: no rules expected the token "import zeep"

🤦 I forgot that macro requires at least one other argument, nvm!

However with let _mod = PyModule::import(py, "zeep").unwrap(); I now get a more descriptive error:

Aha perfect! It looks like your python interpreter is probably a statically-linked one, like pyenv on Mac by default. This has known issues that we haven't worked out quite the best way to resolve yet e.g. see #762 #742.

The notes at #763 might be applicable.

Out of curiosity - are you trying to create a runnable executable which embeds Python? I've just started looking at PyOxidizer the other day, which might also help you get a working program.

@fusillicode
Copy link
Author

🤦 I forgot that macro requires at least one other argument, nvm!

Don't worry I figured it out but I still wasn't able to make it work 😅

Aha perfect! It looks like your python interpreter is probably a statically-linked one, like pyenv on Mac by default. This has known issues that we haven't worked out quite the best way to resolve yet e.g. see #762 #742.
The notes at #763 might be applicable.

Awesome! I'll go check that issues ASAP! Thanks a lot!

Out of curiosity - are you trying to create a runnable executable which embeds Python? I've just started looking at PyOxidizer the other day, which might also help you get a working program.

Actually what I'm trying to do is to to create a single standalone Python module that exposes some functions to interact with a SOAP Web Service.
The module itself would be something like this:

from zeep import Client

CLIENT = Client('http://www.webservicex.net/ConvertSpeed.asmx?WSDL')

def convert_speed(speed):
    result = client.service.ConvertSpeed(speed, 'kilometersPerhour', 'milesPerhour')

From Rust I would then invoke the convert_speed function to get the Web Service response.
I don't think that PyOxidizer is really what I want 🤔

@fusillicode
Copy link
Author

fusillicode commented Nov 16, 2020

Hi @davidhewitt sorry for the bother, just an update about the issue:

what suggested here and here worked like a charm! 👌

I just needed to reinstall the Python version I was using by prefixing the install command with env PYTHON_CONFIGURE_OPTS="--enable-shared".

In my case the install command was asdf install python 3.8 so, what I did was:

env PYTHON_CONFIGURE_OPTS="--enable-shared" asdf install python 3.8

I'm gonna mark the issue as resolved!

Thanks again for the quick support and for all your incredible work! 🙇

@davidhewitt
Copy link
Member

Thanks for following up - glad the other notes were able to help!

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

2 participants