Open phdoerfler opened 6 years ago
@phdoerfler did you ever figure this one out? Having same issue.
@tcullum-gpsw Nope unfortunately I did not but went back to the frustration that is Cython instead
I think cpython crate should be replaced with PyO3 in this repo, PyO3 is more updated and maybe solved this issue.
Getting the same error on MacOSX 10.14.2 using rustc 1.27.2 (58cc626de 2018-07-18)
, following the tutorial exactly, but it seems breaking changes were made since this initial tutorial was done
I made the needed changes to get the tutorial working on recent versions of Rust.
This works on rustc 1.42.0-nightly (0de96d37f 2019-12-19)
and MacOSX 10.14.5.
As @rochacbruno mentioned, it involves using PyO3 instead of CPython.
Switch to Rust nightly (see this link):
cd <path/to/project>
rustup nightly
rustup override set nightly
Change the following files (combining the README example and the PyO3 example):
Cargo.toml:
[package]
name = "pyext-myrustlib"
version = "0.1.0"
authors = ["Bruno Rocha <rochacbruno@gmail.com>"]
edition = "2018"
[lib]
name = "myrustlib"
crate-type = ["dylib"]
[dependencies.pyo3]
version = "0.8.4"
features = ["extension-module"]
src/lib.rs:
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
#[pyfunction]
fn count_doubles(val: &str) -> PyResult<u64> {
let mut total = 0u64;
for (c1, c2) in val.chars().zip(val.chars().skip(1)) {
if c1 == c2 {
total += 1;
}
}
Ok(total)
}
#[pymodule]
fn myrustlib(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(count_doubles))?;
Ok(())
}
Use the following build command on MacOSX:
cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup
The rest of the tutorial should be the same.
To fix the make
command, PyO3 will have to be implemented for all of the functions (which shouldn't be too hard, following the convention shown above).
@gabrielibagon thanks for the final command! it just worked for me. Just out of curiosity: where did get it? is there a way to have it configure globally?
I'm on macOS and ran into this issue:
then I was greeted by this:
which after a lot of scrolling ended in this:
What am I missing?