Executing func() from a different folder - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Executing func() from a different folder (/thread-15349.html) |
Executing func() from a different folder - ebolisa - Jan-14-2019 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. RE: Executing func() from a different folder - mlieqo - Jan-14-2019 Did you also give permissions for the /home/pi directory? Also do you need to run it exactly with this line? python3 test 0You should specify the path: python3 /home/pi/test.py 0 RE: Executing func() from a different folder - ebolisa - Jan-14-2019 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)) |