Permission Error in Installing opencv-contrib-python

Viewed 7391

I am creating a face recognition system using Python and OpenCV on these versions:

Python 3.6.2 (64-bit)
OpenCV 3.3.0

When I try to train the face recognizer:

face_recognizer = cv2.face.createLBPHFaceRecognizer()

and also I tried

face_recognizer = cv2.createLBPHFaceRecognizer()

It gave me attribute error

AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'

When I tried

pip install opencv-python

I got these errors

Exception:
Traceback (most recent call last):
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\commands\install.py", line 342, in run
    prefix=options.prefix_path,
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\req\req_set.py", line 784, in install
    **kwargs
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\req\req_install.py", line 851, in install
    self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\req\req_install.py", line 1064, in move_wheel_files
    isolated=self.isolated,
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\wheel.py", line 345, in move_wheel_files
    clobber(source, lib_dir, True)
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\site-packages\pip\wheel.py", line 323, in clobber
    shutil.copyfile(srcfile, destfile)
  File "c:\users\anushi maheshwari\appdata\local\programs\python\python36-32\lib\shutil.py", line 121, in copyfile
    with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'c:\\users\\anushi maheshwari\\appdata\\local\\programs\\python\\python36-32\\Lib\\site-packages\\cv2\\cv2.cp36-win32.pyd'
4 Answers

I'd been facing the same issue recently. Here's a list of things that went wrong:

  1. You need to uninstall opencv before installing opencv-contrib
  2. Make sure no console is running that has imported cv2 while you execute your installing process
  3. Run the cmd in Administration Mode (Go to the .exe of the cmd program, right click and select 'Run as Administrator')

This should work. Hope this helps!

In case of windows, in cmd try to run pip install using python executable

python -m pip install opencv-python

You can use the below command i.e add user to the command

pip install --user opencv-contrib-python
Related