Python code in node-red

Dear All,

I am writing python code which uses machine learning algorithm like LSTM to forecast the future stock data. The entire code is developed in Jupyter notebook. So the extension of file in ipynb.

Is there any node or a way I can run this code in node-red.

Thanks & Regards
Varun

Hi Varun,
Have you searched the forum? I don't use python, but the forum is full of python related stuff...
E.g. here.

The easier (imho) way would be to either use an exec node to call your program and get the result back, or a daemon node if its a long running app that needs to be fed data.

Hello, one thing you can try is the pythonshell node found here:

You just need to give it the path to your file in the Py file field (for example; /Users/namtrang/main.py ). I am not sure if it runs ipynb extension, though. However, from your jupyter notebook, you can save as .py instead of .ipynb and the code works the same from what I have tried before, so it will hopefully do what you need.

Thanks for your response,

When I use below code in python shell in windows machine I am getting an error exit code: -4058.
location of python in my windows looks to be correct as where is showing below path in windows

C:\Users\CQUGSR>where python
C:\Python38\python.exe
C:\Users\CQUGSR\AppData\Local\Microsoft\WindowsApps\python.exe

[{"id":"b1415d99.fb7fc","type":"tab","label":"Flow 1"},{"id":"6e284a45.462364","type":"pythonshell in","z":"b1415d99.fb7fc","name":"","pyfile":"C:\\Varun\\Test\\test.py","virtualenv":"C:\\Python38\\python.exe","continuous":false,"stdInData":false,"x":341.5,"y":154,"wires":[["da45a630.24ff18"]]},{"id":"a39228fa.530ee8","type":"inject","z":"b1415d99.fb7fc","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":140.5,"y":76,"wires":[["6e284a45.462364"]]},{"id":"da45a630.24ff18","type":"debug","z":"b1415d99.fb7fc","name":"","active":true,"console":"false","complete":"false","x":537.5,"y":233,"wires":[]}]

Thanks & Regards
Varun

Now I am able to run the python scripts using exec node.

In my script I am using pandas. It showing an error saying pandas not found. But I could able to execute and test my complete logic in Juypyter notebook.

Can any one suggest me how to include Pandas and test in node red

Error message:
Command failed: python C:\Varun\Test\LSTM_FC-s30-test.py 1604277501039Traceback (most recent call last): File "C:\Varun\Test\LSTM_FC-s30-test.py", line 15, in import pandas as pdModuleNotFoundError: No module named 'pandas'

Thanks & Regards
Varun

Does that command run if you run it from the command line?

In command line also it is giving warning but execution completes. Looks like in node-red it is stooping the execution

I am not sure it is stopping because of "newline" option not supported in python 2.7.17. I have an constraint of not upgrading to latest version of python too.

data = [['S10']]

opening the csv file in 'w+' mode

file = open('S10.csv', 'w+', newline ='')
write = csv.writer(file)
write.writerows(data)

writing the data into the file

with file:
write = csv.writer(file)
write.writerows(data_FC)

What warning?

This is the warning I am getting

Train on 1613 samples, validate on 823 samples
WARNING:tensorflow:From /home/ubuntu/.local/lib/python2.7/site-packages/tensorfl ow/python/ops/math_grad.py:1250: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
Epoch 1/100
2020-11-02 16:42:54.665935: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-11-02 16:42:54.673302: I tensorflow/core/platform/profile_utils/cpu_utils.c c:94] CPU Frequency: 2299995000 Hz
2020-11-02 16:42:54.673586: I tensorflow/compiler/xla/service/service.cc:168] XL A service 0x561086aa7ef0 executing computations on platform Host. Devices:
2020-11-02 16:42:54.673631: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): ,
2020-11-02 16:42:54.822872: W tensorflow/compiler/jit/mark_for_compilation_pass. cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA _FLAGS=--tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set tha t envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag , not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.

I note that you have opened another thread with a similar problem. Does that mean that this one is fixed?

Yes You are right..Using execute node solved the problem

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.