1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Why "PyRun_SimpleString("from PIL import Image")" does not work in debug mode?

Discussão em 'Python' iniciado por Stack, Outubro 3, 2024 às 16:42.

  1. Stack

    Stack Membro Participativo

    I'm writing a c++ program that use Python library EasyOCR to read some text. I wrote such code:

    Py_Initialize();
    PyRun_SimpleString("import sys");
    PyRun_SimpleString("import easyocr");
    //Other codes


    When I run it in Release mode, it works fine, but if I switch to Debug mode, it reports a run-time error:

    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Python311\Lib\site-packages\easyocr\__init__.py", line 1, in <module>
    from .easyocr import Reader
    File "C:\Python311\Lib\site-packages\easyocr\easyocr.py", line 3, in <module>
    from .recognition import get_recognizer, get_text
    File "C:\Python311\Lib\site-packages\easyocr\recognition.py", line 1, in <module>
    from PIL import Image
    File "C:\Python311\Lib\site-packages\PIL\Image.py", line 100, in <module>
    from . import _imaging as core
    ImportError: cannot import name '_imaging' from 'PIL' (C:\Python311\Lib\site-packages\PIL\__init__.py)


    Then I tried to run

    PyRun_SimpleString("from PIL import Image");


    insteaed of

    PyRun_SimpleString("import easyocr");


    but the same error was reported again:

    Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Python311\Lib\site-packages\PIL\Image.py", line 100, in <module>
    from . import _imaging as core
    ImportError: cannot import name '_imaging' from 'PIL' (C:\Python311\Lib\site-packages\PIL\__init__.py)


    I'm using Visual Studio 2022 on Windows 11 x64 to write my c++ code.My Python version is

    Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32


    My Pillow version is 10.4.0 and easyocr version is 1.7.2

    I have already downloaded the debug symbols via python installer, and set the project's debug config to use the python311_d.lib.

    I want to know why it is reporting such error and what should I do to debug this program in Visual Studio.

    Continue reading...

Compartilhe esta Página