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

maturin failed Caused by: Failed to build a native library through cargo #1019

Closed
1 of 2 tasks
reallyusefulengine opened this issue Jul 20, 2022 · 2 comments
Closed
1 of 2 tasks

Comments

@reallyusefulengine
Copy link

Bug Description

when i run the command "maturin develop" in the virtual env I get the following error:

(py_rust)@192-168-1-10 py_rust % maturin develop
🔗 Found pyo3 bindings
🐍 Found CPython 3.9 at /Users//.local/share/virtualenvs/py_rust-QUdKXKyu/bin/python
💥 maturin failed
  Caused by: Failed to build a native library through cargo

Im using an m1 mac

Your Python version (python -V)

Python 3.9.13

Your pip version (pip -V)

pip 22.1.1 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)

What bindings you're using

pyo3

Does cargo build work?

  • Yes, it works

If on windows, have you checked that you aren't accidentally using unix path (those with the forward slash /)?

  • Yes

Steps to Reproduce

create the file lib.rs:

use pyo3::prelude::*;
use serde::{Deserialize, Serialize};


#[derive(Deserialize, Debug)]
struct Data {
    name: String,
    value: i32
}

fn sum(input: &str) -> i32 {
    let parsed: Data = serde_json::from_str(input).unwrap();
    parsed.name.len() as i32 + parsed.value
}

#[pymodule]
fn py_rust(_py: Python, m: &PyModule) -> PyResult<()> {
  Ok(())
}

toml:

[package]
name = "py_rust"
version = "0.1.0"
edition = "2021"

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

[dependencies]
pyo3 = { version = "0.16.5", features = ["extension-module"] } 
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

create the virtual env and run maturin develop

@reallyusefulengine reallyusefulengine added the bug Something isn't working label Jul 20, 2022
@messense
Copy link
Member

messense commented Jul 20, 2022

https://maturin.rs/tutorial.html

[lib]
# "cdylib" is necessary to produce a shared library for Python to import from.
crate-type = ["cdylib"]

You missed the crate-type = ["cdylib"] configuration. Although we should improve the error message. Ref #881

@messense messense removed the bug Something isn't working label Jul 20, 2022
@reallyusefulengine
Copy link
Author

Thank you for such a quick response, that really fixed the error so much appreciated.

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