subprocess.call()权限被拒绝错误 [英] Permission Denied Error with subprocess.call()

查看:203
本文介绍了subprocess.call()权限被拒绝错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将某些nrrd文件转换为Dicom文件,并且我有此代码段

Im trying to convert some nrrd files to Dicom files,and i have this code snippet

NRRD_TO_DICOM = '/mnt/sdc1/user/6363/'
def NRRDToDICOM(filename, output_folder_name):
    subprocess.call([NRRD_TO_DICOM, filename, output_folder_name])

NRRDToDICOM('ARTERIAL.nrrd', '/mnt/sdc1/user/6363/ARTERIAL/')

我尝试从jupyter笔记本上运行它,但这给了我

I tried running this from my jupyter notebook,but it gives me

 PermissionError                           

Traceback (most recent call last)
<ipython-input-6-5ee279d7c7db> in <module>()
      3     subprocess.call([NRRD_TO_DICOM, filename, output_folder_name])
      4 
----> 5 NRRDToDICOM('ARTERIAL.nrrd', '/mnt/sdc1/Ryan/6363/ARTERIAL/')

<ipython-input-6-5ee279d7c7db> in NRRDToDICOM(filename, output_folder_name)
      1 NRRD_TO_DICOM = '/mnt/sdc1/Ryan/6363/'
      2 def NRRDToDICOM(filename, output_folder_name):
----> 3     subprocess.call([NRRD_TO_DICOM, filename, output_folder_name])
      4 
      5 NRRDToDICOM('ARTERIAL.nrrd', '/mnt/sdc1/Ryan/6363/ARTERIAL/')

PermissionError: [Errno 13] Permission denied

之后,我将保存的文件另存为py文件,并在执行后从终端运行它

After which i saved the saved the file as a py file and ran it from the terminal after doing

chmod +x /mnt/sdc1/user/6363/ARTERIAL/

chmod +x /mnt/sdc1/user/6363/

但是同样的错误仍然存​​在, 预先感谢任何有关如何解决此问题的建议.

But the same error persists, Any suggestions on how i may fix this will be very helpful,Thanks in advance.

推荐答案

您试图将/mnt/sdc1/user/6363/作为命令的名称运行,但显然不是.

You are attempting to run /mnt/sdc1/user/6363/ as the name of a command, but obviously, it isn't one.

尚不清楚您实际要运行什么,但这根本不是正确的方法.

It's not clear what you are attempting to actually run, but this is not the right way to do that at all.

您作为subprocess.Popen()的第一个参数传递的列表中的第一项及其各种便利包装必须是可执行文件 ,就像您需要键入命令而不是目录一样名称,在shell提示符下.

The first item in the list you pass as the first argument to subprocess.Popen() and its various convenience wrappers needs to be an executable file just like you would need to type a command, not a directory name, at the shell prompt.

我猜你的代码应该看起来像

I'm guessing your code should look something like

def NRRDToDICOM(filename, output_folder_name):
    subprocess.call(['/usr/bin/nrrdtodicom', filename, output_folder_name])

如果可执行文件已经在您的PATH上,则可能不需要该可执行文件的路径(因为它应该是-我主要放在/usr/bin/中是为了明确表明我们正在谈论的是这种类型的东西),当然,如果您绝对坚持可以将其保存在变量中,但这似乎是一件很奇怪的事情(尽管如果可以将具有所需API的命令安装在多个不同的名称下,则可能是这样)使其可配置或至少易于更改是很有意义的.

where the path to the executable might not be necessary if it's already on your PATH (as it probaby should be -- I mainly put in the /usr/bin/ to make it really explicit that we are talking about that type of thing), and you can of course save it in a variable if you absolutely insist, but that seems like a weird thing to want here (though if a command with the required API could be installed under a number of different names, perhaps then it would make sense to make it configurable or at least easy to change).

这篇关于subprocess.call()权限被拒绝错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆