I participate in a Python project, which utilizes industry cameras, such as Basler's or Allied Vision's, to inspect quality of products' packaging. I used Basler's Python Pylon API to communicate with the camera. I stumbled upon a problem that was fixable only from the Pylon C++ API. Since it is impossible for Python and C++ APIs to talk to each other, I had to move camera object's creation and management into the C++ code. There is a separate implementation for every camera manufacturer (vimba.py for Allied Vision, basler.py for Basler, etc.), but all of them must satisfy the inner common interface used by the camera manager class in our project so that they remain compatible (Init
, Open
, etc.), so I have decided to not touch the signatures, yet simply swap their bodies with the calls to the C functions (exported in the PYD file, which, in turn, is imported by basler.py), which now contain the actual Basler implementation code. Basically speaking, basler.py imports the PYD file with the functions and basler.py's methods call them.
I have read that you must Py_Initialize
before calling any Python API functions so that embedded Python is initialized correctly. And.... I think it doesn't work for me, because, when there's the need to use any integer from the Python small int ranges ([-5, 256]), then there is a segmentation fault. I should note that I run everything in a venv.
What have I tried:
- prioritizing venv Python in the
PATH
, - modifying
PYTHONPATH
andPYTHONHOME
anyhow, - adding paths to
sys.path
, - checking all paths in
pyvenv.cfg
, - trying the actual system interpreter instead of the venv one to run the application (and prioritizing it in the
PATH
), - checking
PyErr_Occurred
andPy_IsInitialized
, - checking literally every Python C API call (and I stick with this now),
- running the app as an administrator,
- reinstalling Python and even completely resetting Windows to the clean and new state.
I also should note there are no system codec or missing packages errors, like many other users experience. I can easily check if e.g. small integers have been initialized by calling PyLong_FromLong(1L);
, which causes a crash already. Is there anything I could have missed?
Best regards