Errno 13权限在mac上被拒绝

时间:2016-12-06 13:36:51

标签: python permission-denied errno

我只是测试如何从一个.py文件调用外部.py文件。 我有2个.py文件,都在同一目录中。这是主要的代码(runext.py假设调用ext.py):

import subprocess
subprocess.call("/Users/training/PycharmProjects/MarcouFirstProject/ext.py")

ext.py只是print("hey this actually worked")

但是,每次运行runext.py时,都会收到以下错误消息:

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

我不知道为什么它会拒绝许可。这是在学校的计算机上(我在编程课程中)如果有帮助的话。

感谢。

1 个答案:

答案 0 :(得分:0)

您无权执行文件/Users/training/PycharmProjects/MarcouFirstProject/ext.py

您可以使用chmod:

添加权限+x

chmod +x /Users/training/PycharmProjects/MarcouFirstProject/ext.py

或者,你可以明确地使用python:

import subprocess
subprocess.call("python /Users/training/PycharmProjects/MarcouFirstProject/ext.py")