No such file or directory

I have Docker Swarm with node-red running. I have used a simple flow to try and read a HelloWorld.py script [EXEC] with no joy. I had modified it to “cat /etc/pam.conf” and it works. I am sure I am missing something simple, any assistance would be appreciated.

Error:
payload: "python: can’t open file ‘/home/pi/HelloWorld.py’: [Errno 2] No such file or directory↵"

Export of the flow:

[{"id":"3f0a9383.02189c","type":"tab","label":"Flow 1"},{"id":"83d6a159.11f9a","type":"inject","z":"3f0a9383.02189c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":100,"y":120,"wires":[["1683f7e8.ee1dd8"]]},{"id":"6c98bc6a.acd014","type":"debug","z":"3f0a9383.02189c","name":"","active":true,"console":"false","complete":"true","x":510,"y":120,"wires":[]},{"id":"1683f7e8.ee1dd8","type":"exec","z":"3f0a9383.02189c","command":"python -u /home/pi/HelloWorld.py","addpay":false,"append":"","useSpawn":false,"timer":"","name":"test","x":290,"y":200,"wires":[[],["6c98bc6a.acd014"],["6c98bc6a.acd014"]]}]

pi@pi2:~ $ cat HelloWorld.py
#!/user/bin/python
# Hello World python Program
print "Hello World!";

pi@pi2:~ $ python HelloWorld.py
Hello World!

Hello, use this button to Formate your code

@Tangental you need to edit your previous post (use the pen icon at the bottom) and insert a line containing three back tick characters (to the left of the 1 key on my keyboard) before your flow and another such line after your flow. Then it will tell Discourse not to convert the quotes to smart quotes and we will be able to import it.

1 Like

@Tangental

do you actually have the line ‘Hello World python Program’ in your program?
Have you tried running the python program from the cli on the pi?

Yes the code is like I copied it up there. I removed that line and displayed the results below from the cli.

pi@pi2:~ $ python HelloWorld.py
Hello World!

Thanks,

Thanks I have updated the question.

I can’t help you with docker, but at least the python will now work without returning an error :grinning:

what user is docker running as ? If not running as Pi it may not have access to that directory.

I dug into the permissions and tried multiple ways, until I found that the docker container did not have the file to be accessible.

so I had to copy the file to the container, using Vlad's Docker Copy Example I was able to make a copy in the context that Node-Red could access.

pi@pi2:/home $ sudo docker container ls | grep mynodered | cut -d' ' -f1
c22f8d1433e8
then add that to the docker command...
sudo cat /home/pi/HelloWorld.py | docker exec -i c22f8d1433e8 sh -c 'cat > /home/HelloWorld.py'
note the /home/pi/ did not exist, so I placed it in the root of the home folder.

one step closer...
next I modified the [EXEC] to cat that file and it worked!

Then modified it to run the HelloWorld.py like:
python -u /home/HelloWorld.py

msg : Object
object
_msgid: "f583bcb9.d7203"
topic: ""
payload: "Hello World!↵"

This worked!
so a little more complicated than expected to get the python scripts available... but workable.

Now I have to find out how to sudo another python script so access the GPIO pins. ultrasonic.py :slight_smile: