I installed python via anaconda on an EC2 Ubuntu Instance.
The command which python returns */home/ubuntu/anaconda3/bin/python*
Jenkins is instead installed in */var/lib/jenkins*
I am trying to run a simple "Hello World" script saved on a file named *test.py* and located within the */home/ubuntu/scripts/* folder.
While running *python /home/ubuntu/scripts/test.py* works on terminal, it fails as an "Execute shell" build step in Jenkins.
Why and how do I configure Jenkins to run python scripts step by step?
The issue was that the anaconda python installation was only available to the user "ubuntu". For Jenkins to be able to run python scripts, the "jenkins" user needs to use that installation.
To solve the problem, this is what I did:

Logged in as jenkins with the command sudo su -s /bin/bash jenkins
Edited the python install location as export PATH=/home/ubuntu/anaconda3/bin:$PATH
Checked that the path is correct through which python
Logged back as ubuntu user
Restarted Jenkins through sudo service jenkins restart (not sure if necessary)

Now I can run python scripts through Jenkins.
How to configure Jenkins to run Python scripts?