Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
usa opencv en heroku con node.js

Estoy llamando a un script de python con PythonShell en javascript.

mi función javascript está debajo

 function runPythonScript(pythonPath, pythonScript) { console.log('ND - server - run python without argument'); let myPath = __dirname; console.log('myPath: ', myPath); //let pythonPath = pythonPath; console.log('pythonPath: ', pythonPath); //let pythonScript = pythonScript; console.log('pythonScript: ', pythonScript); //Here are the option object in which arguments can be passed for the python_test.js. let options = { mode: 'text', pythonOptions: ['-u'], // get print results in real-time scriptPath: myPath + pythonPath //If you are having python_test.py script in same folder, then it's optional. //args: ['xxxx'] //An argument which can be accessed in the script using sys.argv[1] }; return new Promise(function(resolve, reject) { PythonShell.run(pythonScript, options, function(err, result) { if (err) reject(err); // result is an array consisting of messages collected //during execution of script. console.log('data: ', result.toString()); let parsedData = JSON.parse(JSON.stringify(result.join('\n'))); console.log('data type: ', typeof parsedData, ' of length ', parsedData.length); parsedData = parsedData.replace(/'/g, `"`); // replace the quote by the double quotes for parsing the string to a JSON object. parsedData = JSON.parse(parsedData); console.log('parsed data type: ', typeof parsedData); //console.log('parsed data: ', parsedData); resolve(parsedData); }); }); } async function main() { try { let counterpartyData = await runPythonScript('/python','test.py'); console.log('ND - server - counterparty data: ', counterpartyData); } catch (e) { console.error(e); } } main();

En esta función, llamo al script de python aquí abajo

 import cv2 mydict ={ "counterParty_Car": "Ford", "counterParty_CarPlate" : "O XXX YYY", "counterParty_Name" : "John Snow", "counterParty_Policy": "0123456789" } print(mydict)

Si elimino la import cv2 en el script de python, no hay error. Pero si quiero agregar la importación cv2 (porque lo necesitaba para los siguientes pasos). Aparece un error que significa que no hay ningún módulo cv2.

 /app/node_modules/libheif-js/libheif/libheif.js:1 2022-01-12T15:14:56.167971+00:00 app[web.1]: var Module=typeof Module!=="undefined"?Module:{};((function(){var [...]

Probé las respuestas propuestas en otras preguntas y en otro sitio web, pero nada funciona. ¿Tienes alguna idea de cómo solucionar este problema?

en mi archivo requirment.txt heroku, tengo opencv-python-headless==4.5.4.60

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda