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

prepare_freethreaded_python in crate pyo3 on OSX Big Sur #1686

Closed
sansyrox opened this issue Jun 22, 2021 · 8 comments
Closed

prepare_freethreaded_python in crate pyo3 on OSX Big Sur #1686

sansyrox opened this issue Jun 22, 2021 · 8 comments

Comments

@sansyrox
Copy link
Contributor

🐛 Bug Reports

When reporting a bug, please provide the following information. If this is not a bug report you can just discard this template.

I am getting the error : prepare_freethreaded_python in crate pyo3 on OSX Big Sur when I am using the prepare_freethreaded_python function.

🌍 Environment

  • Your operating system and version: OSX Big Sur
  • Your python version: 3.9
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?:
  • Your Rust version (rustc --version): 1.50.0 (cb75ad5db 2021-02-10
  • Your PyO3 version: 0.13.2
  • Have you tried using latest PyO3 main (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?:

💥 Reproducing

Please provide a minimal working example. This means both the Rust code and the Python.

use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

use std::future::Future;

#[pymodule]
pub fn robyn(py: Python<'_>, m: &PyModule) -> PyResult<()> {
    pyo3_asyncio::try_init(py).unwrap();
    pyo3::prepare_freethreaded_python();

    Ok(())
}


Error message:

error[E0425]: cannot find function `prepare_freethreaded_python` in crate `pyo3`
  --> src/lib.rs:29:11
   |
29 |     pyo3::prepare_freethreaded_python();
   |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `pyo3`

Please also write what exact flags are required to reproduce your results.

@mejrs
Copy link
Member

mejrs commented Jun 22, 2021

That function is not available when compiling for PyPy - is that what you are running?

@davidhewitt
Copy link
Member

It's also unavailable on 0.13.2 if your Python interpreter does not claim to have the Py_ENABLE_SHARED config var set. You can check:

>>> import sysconfig
>>> sysconfig.get_config_var("Py_ENABLE_SHARED")
1

If you don't get "1" output above, this could explain it.

We decided that disabling this API in this way was a mistake in #1553, so in the very-soon-to-be-released 0.14 or main you shouldn't experience this problem.

@sansyrox
Copy link
Contributor Author

sansyrox commented Jun 23, 2021

Thank you ,@davidhewitt ! Switching to main solved this issue. But , it has introduced a new issue.

-> src/process.rs:34:53
   |
34 |                 let contents: &str = output.extract(py).unwrap();
   |                                                     ^^ expected struct `pyo3::python::Python`, found struct `pyo3::Python`
   |
   = note: perhaps two different versions of crate `pyo3` are being used?

Any idea how do I fix it?

My cargo.toml file looks like this

[dependencies]
tokio = { version = "1.7.0", features = ["full"] }
dashmap = "4.0.2"
flume = "0.10.7"
pyo3 = {git = "https://github.com/PyO3/pyo3/",branch = "main", features = ["extension-module"]}

@davidhewitt
Copy link
Member

Do you have pyo3 anywhere else in your dependencies? As the error suggests, you have two versions of pyo3 in use.

@sansyrox
Copy link
Contributor Author

@davidhewitt , I am also using pyo3-asyncio. Is that a possible source of conflict?

@messense
Copy link
Member

try patch instead

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

[patch.crates-io]
pyo3 = {git = "https://github.com/PyO3/pyo3/",branch = "main", features = ["extension-module"]}

https://doc.rust-lang.org/edition-guide/rust-2018/cargo-and-crates-io/replacing-dependencies-with-patch.html

@sansyrox
Copy link
Contributor Author

Thank you, @messense . Your solution works for me! 🥳

@davidhewitt
Copy link
Member

Glad to hear. As the original problem has been solved, I'm going to close this issue out.

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

4 participants