Hello …
I am trying to let python script to call another python script.
Running command below the python script to call the test1.py script in Ubuntu 18.04
sudo python3 test1.py
The test1.py contains the code below
import os
count = 1
if count == 1:
os.system('/opt/pythonm/test.py')
count = count + 1
print('Done')
else:
print('Not Meet the conditio and Exit')
exit
However, I got the error below
sh: 1: /opt/pythonm/test.py: Permission denied
Done
Thank you for your help.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
My thinking would be add python3 before the file location.
Could be a system permissions issue, I wouldn’t call it though, I would import it and run within the current app or use threading to run along side.
The “Permission denied” error means that the user who is running the Python script doesn’t have sufficient permission to execute the other script.
To fix this, you will need to make test.py executable. You can do this by running the following command:
sudo chmod +x /opt/pythonm/test.py
The chmod +x command changes the permissions of the file to make it executable.
Also, it’s important to note that if test.py is a Python script, it should start with a shebang line that specifies the interpreter for the script, which is Python in this case. If it doesn’t have one, you should add the following line at the very top of test.py:
#!/usr/bin/env python3
This tells the operating system to run the script using Python 3.
Finally, if test.py needs to be run with Python specifically (rather than being run directly as an executable), you may want to change your os.system call to include the python command:
os.system('python3 /opt/pythonm/test.py')
In this case, ensure that the user running the script has permission to use Python to execute scripts.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.