尝试在Ubuntu中安装opencv4nodejs时权限被拒绝

时间:2020-10-28 06:39:36

标签: node.js opencv npm appium appium-android

我尝试使用以下命令在opencv4nodejs中安装Ubuntu-20.04,并且我的节点版本为v12.19.0

sudo npm i -g opencv4nodejs

但是遇到那些错误

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

2 个答案:

答案 0 :(得分:2)

1。使用sudo运行npm install可能会导致权限问题。您可以尝试完全删除node_modules目录,然后在不使用sudo的情况下重新运行npm安装它。

  1. 还要确保您有权写入要安装的目录吗?

  2. 如果仍然不起作用,请遵循以下步骤: sudo npm install -g opencv4nodejs --unsafe-perm = true --allow-root

答案 1 :(得分:1)

这是将opencv4nodejs安装到Linux OS或Raspberry pi(Raspberry Pi OS)的完整指南

配置

   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

要安装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

要安装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)

在同一文件夹的index.js和node_modules中

const cv = require("opencv4nodejs");

在不同文件夹中的index.js和node_modules中

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

!您不需要为每个文件夹安装opencv4nodejs 您可以简单地以上述方式调用

希望大家能理解... 任何问题都可以随意询问...

谢谢