问题
I am simply testing how to call external .py files from one .py file. I have 2 .py files, both in the same directory. Here is the code for the main one (runext.py suppose to call ext.py):
import subprocess
subprocess.call("/Users/training/PycharmProjects/MarcouFirstProject/ext.py")
ext.py is just print("hey this actually worked")
However, every time I run runext.py, I get this error message:
Traceback (most recent call last):
File "/Users/training/PycharmProjects/MarcouFirstProject/runext.py", line 2, in <module>
subprocess.call("/Users/training/PycharmProjects/MarcouFirstProject/ext.py")
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
I don't know why it denies permission. This is on a school computer (I'm in a programming class) if that helps.
Thanks.
回答1:
You don't have the permissions to execute the file /Users/training/PycharmProjects/MarcouFirstProject/ext.py
You can add the permission +x
by using chmod:
chmod +x /Users/training/PycharmProjects/MarcouFirstProject/ext.py
Or, you can use python explicitly:
import subprocess
subprocess.call("python /Users/training/PycharmProjects/MarcouFirstProject/ext.py")
来源:https://stackoverflow.com/questions/40996724/errno-13-permission-denied-on-mac