MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

Face Recognition - File can't be opened for writing

  • Well the Mirror and the modules are working for now.

    The next step is to seperate modules to specific users so i use the FaceRec lib.

    I trained 10 images first for a quick test.
    When im trying to start MMv2 with this module he pushes this error message:

    [MMM-Facial-Recognition] Facerecognition started...
    [MMM-Facial-Recognition] Loading training data...
    [MMM-Facial-Recognition] ALGORITHM: LBPH
    Whoops! There was an uncaught exception...
    { [Error: OpenCV Error: Unspecified error (File can't be opened for writing!) in load, file /build/opencv-ISmtkH/opencv-, line 325
    Traceback (most recent call last):
      File "modules/MMM-Facial-Recognition/facerecognition/", line 59, in 
    cv2.error: /build/opencv-ISmtkH/opencv- error: (-2) File can't be opened for writing! in function load
      executable: 'python',
      options: null,
      script: 'modules/MMM-Facial-Recognition/facerecognition/',
      args: [ '{"recognitionAlgorithm":1,"lbphThreshold":50,"fisherThreshold":250,"eigenThreshold":3000,"useUSBCam":false,"trainingFile":"~/MagicMirror/modules/MMM-Facial-Recognition/training.xml","interval":1,"logoutDelay":15,"users":["Marvin"],"defaultClass":"default","forAllClass":"for_all"}' ],
      exitCode: 1 }
    MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?
    If you think this really is an issue, please open an issue on GitHub:

  • Moderator

    Looks like it doesn’t have permission to open your trainingFile:

    cv2.error: /build/opencv-ISmtkH/opencv- error: (-2) File can’t be opened for writing! in function load

    Notice the File can't be opened for writing message.

    Wherever it’s trying to create that file, the main process running MM can’t write to that location.

  • Admin

    Probably it does not even exist in that path. Be sure to add the training file path to the conduct of put it in the module folder.

  • The XML file is located in the module path mmm-facial-recognition.
    I will answer more precisely when I’m back hat home

  • So, my internet is back after a day 😃

    I reinstalled the module with deleting & cloning it again.

    The training.xml is located in


    I installed open cv with

    sudo apt-get install libopencv-dev python-opencv

    after this, i went into the folder


    and typed

    sudo npm install

    I still get the same error MSG 😞

    i also changed the rights on the training.xml to Anyone/Anyone/Anyone

    please help

  • Admin

    @feuerball try putting it somewhere else and set the trainingFile setting in your config 🙂

  • well i rewrote the destination of the file @ the config again and now it works.

    seems like there was an error anywhere 😃

    thanks 🙂

  • @feuerball I didn’t understand what is the config

    I am having the same error

Log in to reply