Permission denied while trying to install opencv4nodejs in Ubuntu

梦想与她 提交于 2020-11-29 23:54:21

问题


I was trying to install opencv4nodejs in Ubuntu-20.04 using the following command and my node version is v12.19.0

sudo npm i -g opencv4nodejs

But getting those errors

info install installing opencv version 3.4.6 into directory: /usr/lib/node_modules/opencv4nodejs/node_modules/opencv-build/opencv
ERR! Error: Command failed: mkdir -p opencv
mkdir: cannot create directory ‘opencv’: Permission denied
 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! opencv-build@0.1.9 install: `node ./install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the opencv-build@0.1.9 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-10-28T06_33_21_090Z-debug.log

回答1:


1.Running npm install with sudo might be causing a permissions problem. You could try completely removing the node_modules directory and re-running npm install it without sudo.

  1. Also make sure you have permission to write to the directory you're installing in?

  2. If it still doesn't work plz follow this : sudo npm install -g opencv4nodejs --unsafe-perm=true --allow-root




回答2:


This is complete guide to install opencv4nodejs to Linux OS or Raspberry pi (Raspberry Pi OS )

configuration

   01- sudo raspi-config  expand file system  // this is for raspberry pi 
   After Reboot (sudo reboot now)
   02- df -h (To check expand file system)
   03- sudo apt-get update && sudo apt-get upgrade -y
   04- sudo passwd root  // set up your root password
   Reboot

To Install NodeJS

   01- sudo apt-get install git -y
   02- curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -  // replase 12 with latest nodejs (LTS) version
   03- sudo apt-get install nodejs -y
   04- sudo apt-get install gcc g++ make

To Install opencv4nodejs

01. sudo apt-get install cmake -y
02. sudo npm install -g node-gyp

I am using this steps for raspberry pi os
03. sudo nano /etc/dphys-swapfile
    (Increase the CONF_SWAPSIZE from 100 to 1024)
        sudo /etc/init.d/dphys-swapfile stop
        sudo /etc/init.d/dphys-swapfile start

cd to home dir..
04. mkdir opencv
05. cd opencv
06. sudo npm init -y

07. su  
    // Enter your setup root password

08. sudo npm install --save opencv4nodejs

09. sudo nano /etc/dphys-swapfile
    (Set the CONF_SWAPSIZE back to 100)

In index.js and node_modules in same folder

const cv = require("opencv4nodejs");

In index.js and node_modules in not in same folder

const cv = require("path/opencv/node_modules/opencv4nodejs");

! you don't need to install opencv4nodejs for each folders You can simply call that above way

Hope guys you can understand it... Any questions feel free to ask...

Thank you



来源:https://stackoverflow.com/questions/64567610/permission-denied-while-trying-to-install-opencv4nodejs-in-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!