1

I am trying to run a python script from a node.js- cloud functions index file. in order to access python script, I am also using "python-shell" ... the problem is every time I run deploy my functions of the index.js file, it prints this error:

Error: python: can't open file '../Python36/fListener.py': [Errno 2] 
                     No such file or directory

at PythonShell.parseError (/user_code/node_modules/python-
 shell/index.js:190:17)
at terminateIfNeeded (/user_code/node_modules/python-shell/index.js:98:28)
at Socket.<anonymous> (/user_code/node_modules/python-shell/index.js:78:9)
at emitNone (events.js:91:20)
at Socket.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)

also, I tried to create python project in the node.js 'functions' folder but it's pointing me on different 'import' errors on libraries which I am trying to use on python's script.something like this:

 File "py_project/fListener.py", line 1, in <module>
      import sseclient

what is the correct way to execute python script via node.js cloud functions??

thanks.

arudzinska
  • 3,152
  • 1
  • 16
  • 29
m.d
  • 123
  • 2
  • 9
  • It would be helpful if you posted your directory structure. – Matt Morgan Jan 07 '18 at 12:21
  • C:\Users\mkdan\nodejs\functions\py_env - this is where my 'Lib', 'Scripts' ..etc. C:\Users\mkdan\nodejs\functions\social_py - is where my python's script – m.d Jan 07 '18 at 12:26
  • the 'index.js' file is also in - C:\Users\mkdan\nodejs\functions – m.d Jan 07 '18 at 12:33

1 Answers1

0

Here's a little bit different approach for calling a Python script from a Cloud Function, without usage of python-shell. The idea is to package the Python code with PyInstaller ("a program that freezes (packages) Python programs into stand-alone executables") into a self-executable unit that is later used by a function executed by a node.js script. It was discussed more in depth in this Stack Overflow topic.

arudzinska
  • 3,152
  • 1
  • 16
  • 29
  • Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. See [how to answer](https://stackoverflow.com/help/how-to-answer) – SilverNak Feb 20 '18 at 16:06