How to obtain PIL.Image and PIL.ImageOps? (Pillow) #3001
-
Hi, I'm rewriting a piece of software from Python to Rust. This piece relies on For some reason, it does not permit using from PIL import Image So the following Rust code did not work for me: Python::with_gil(|py| {
// ...
let (Image, ImageOps) = {
let PIL = py.import("PIL")?;
(
PIL.getattr("Image")?,
PIL.getattr("ImageOps")?,
)
};
// ...
} I tried obtaining them via a Python::with_gil(|py| {
// ...
let (Image, ImageOps) = {
let PIL = py.import("PIL")?;
let dict = PIL.dict();
(
dict.get_item("Image").ok_or(PyImportError::new_err("module 'PIL' has no attribute 'Image'"))?,
dict.get_item("ImageOps").ok_or(PyImportError::new_err("module 'PIL' has no attribute 'ImageOps'"))?,
)
};
// ...
} but I failed again. I guess I should somehow use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I had a chat with Chat GPT and it proposed me this approach: import importlib
PIL = importlib.import_module('PIL.Image') and it worked. Then I tried doing it like this: import PIL.Image and it worked too! Hope it will help anyone! |
Beta Was this translation helpful? Give feedback.
-
For future reference, please include the error(s) you're getting with such reports. It is much easier to see for use what could be going wrong. |
Beta Was this translation helpful? Give feedback.
I had a chat with Chat GPT and it proposed me this approach:
and it worked. Then I tried doing it like this:
and it worked too! Hope it will help anyone!