'Not asking for camera permission when calling requestAccessForMediaType using Python and PyInstaller

I am trying to bundle a python app on macOS and this app needs access to the camera. I use PyInstaller to package my app to work on OSX Mojave.

To give access to the camera to my app I added the following lines in Info.plist :

    <key>NSCameraUsageDescription</key>
    <string>Camera is needed.</string>

And in my python code I use the following lines to ask for camera permission :

AVFoundation.AVCaptureDevice.requestAccessForMediaType_completionHandler_(AVFoundation.AVMediaTypeVideo, grant_camera_access)

with the function grant_camera_access being :

def grant_camera_access(access):
    CAMERA_ACCESS = True

When I launch my app with python3 from the terminal it asks for camera access and everything works.

But after packaging my app with PyIntstaller no permission are asked. I have looked a lot and haven't found an answer to my problem yet. Does anybody have an idea of what I am doing wrong ?

Here is the command line I use to bundle my app :

pyinstaller --add-data 'res:res' -i myicone.icns --osx-bundle-identifier com.bundle.identifier --windowed myapp.py

Thanks for your advice.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source