Skip to content

Cant build example #300

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

Closed
lukaseller opened this issue Dec 5, 2018 · 5 comments
Closed

Cant build example #300

lukaseller opened this issue Dec 5, 2018 · 5 comments
Labels

Comments

@lukaseller
Copy link

I have a problem with the following example .

I copied the source code in my lib.rs

#![feature(specialization)]

#[macro_use]
extern crate pyo3;

use pyo3::prelude::*;

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

/// This module is a python moudle implemented in Rust.
#[pymodule]
fn rust_py(py: Python, m: &PyModule) -> PyResult<()> {
    m.add_wrapped(wrap_function!(sum_as_string))?;

    Ok(())
}

And set my cargo.toml file to:

[package]
name = "rust-py"
version = "0.1.0"

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

[dependencies.pyo3]
version = "0.5.2"
features = ["extension-module"]

When I do :

cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup

I get the following error regarding the pymodule argument:

error[E0658]: The attribute pymodule is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)

My setup:

  • MacOs 10.14
  • rustc 1.32.0-nightly

Any ideas what could be the issue? Thanks

@konstin
Copy link
Member

konstin commented Dec 5, 2018

The problem is that you're using the documentation for master, while building on stable (0.5.2). stable docs

@lukaseller
Copy link
Author

Thank you for your help!
But it seems that there is another issue:

error[E0119]: conflicting implementations of trait `python::IntoPyDictPointer` for type `(_, _)`:
   --> /Users/lukas/.cargo/registry/src/github.com-1ecc6299db9ec823/pyo3-0.3.2/src/objects/dict.rs:246:1
    |
231 | / impl <K, V, I> IntoPyDictPointer for I

232 | | where
233 | |     K: ToPyObject,
234 | |     V: ToPyObject,
...   |
243 | |     }
244 | | }
    | |_- first implementation here
245 |
246 |   impl<K: ToPyObject, V: ToPyObject> IntoPyDictPointer for (K, V) {
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_, _)`
    |
    = note: upstream crates may add new impl of trait `std::iter::Iterator` for type `(_, _)` in future versions

This seems to be related to this issue.
It seems that the stable documentation does still have version 0.3 in the dependencies for the getting started example.

@lukaseller
Copy link
Author

Update: It seems to be working with version version = "0.5.2"
I guess changing this to the current version could safe a lot of confusing for people how are just starting out.

Thank you anyway for your great work here :)

@shawn-xy
Copy link

shawn-xy commented Dec 6, 2018

Met the same issue. I made it work with git clone the master and add
path = "/path/to/the/cloned/repo" .

@konstin
Copy link
Member

konstin commented Dec 6, 2018

I'm sorry for the inconvenience; The problem is that the documentation references 0.3 in the 0.5 documentation. This has been fixed in master (#293), but we can't just make a new release since we've already merged some breaking changes for 0.6.

@shawn-xy Please don't do that. Cargo has sufficient support for git dependencies and for overriding dependencies, which will avoid accidentally forking pyo3.

@konstin konstin closed this as completed Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants