Python Forum

Full Version: Executing func() from a different folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I've a test.py containing a func(x) in my /home/pi directory.

I need to execute the func(x) from /var/www/html directory with the code "python3 test 0". Said code works within the pi directory but not from outside of it.

I've given the www-data group permissinon to test.py but cannot solve the path '/home/pi' issue.

Any help is appreciated.
Did you also give permissions for the /home/pi directory?

Also do you need to run it exactly with this line?
python3 test 0
You should specify the path:
python3 /home/pi/test.py 0
Thanks. Not sure if it's the right way but I solved my issue by creating a local file point to the original located in a different folder as such:

#!/usr/bin/env python

import sys
sys.path.insert(0, '/home/pi/.')

from gpio import ledsOn

if __name__ == '__main__':
  n = int(sys.argv[1])
  print(ledsOn(n))