python open()-拒绝访问 [英] python open() - access denied

查看:99
本文介绍了python open()-拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我关于stackoverflow的第一篇文章,因此,如果出现问题,我很想学习!

This is my first post on stackoverflow, so if somethings wrong I'm eager to learn!

我正在用python为Cinema 4d编程一个插件.一切都可以在Mac上运行,但是我在Windows上遇到的问题有待我解释.

I'm programming a plugin for Cinema 4d with python. Everything works on Mac, but I'm having problems on Windows with what I'm about to explain.

如果在renderserver上进行渲染,则插件需要服务器的路径.我希望用户输入一次路径,然后将其存储在.txt文件中.

The plugin needs a path to a server, in case of rendering on a renderserver. I want the user to enter the path once, and to then store it in a .txt file.

对于c4d,通过将插件拖放到plugin文件夹中来安装插件,例如:

for c4d, plugins are being installed, by draging-and-droping the plugin into the plugin folder at for example:

C:/程序文件/Maxon/Cinema4D/插件/NewPluginGoesHere

C:/programm files/Maxon/Cinema4D/Plugins/NewPluginGoesHere

为了保持所有内容的美观和整洁,我也希望在插件文件夹中包含pathToServer.txt(仅与路径存储一行的文本文件).在将插件安装(放到)文件夹中时,.txt文件已经存在->插件未创建.

In Order to keep everything nice and clean, I want the pathToServer.txt (text file that only stores one line with the path) in the plugin folder as well. When Installing (droping) the plugin into said folder, the .txt file is already there -> Not created by the plugin.

问题来了:

我用

pathFile = open(pathToPathFile, "w")
pathFile.write(pathToServerFolder)

在Mac上运行正常,但会抛出

Works fine on mac, but throws

IOError: [Errno 13] Permission denied: 'C:\\Program Files\\MAXON\\CINEMA 4D R14\\plugins\\MultiLayerRender\\Renderserverpath.txt'

在Windows上.

我对使用python执行此类任务(例如文件管理)缺乏经验.

I'm pretty inexperienced with using python for such tasks (like file management).

然后我尝试了以下操作:

I then tried the following:

pathFile = subprocess.Popen(pathToPathFile, stdin = subprocess.PIPE, stdout = subprocess.PIPE, shell = True)
pathFile.communicate(input = pathToServerFolder)
pathFile.stdin.close()

哪个没有给我一个错误,但是它似乎也什么也没做:/

Which doesn't give me an error, but it also doesn't seem to do anything :/

我读了有关子进程的python文档,但是那真的并没有帮助我,如果有的话,这使我感到困惑.

I read throung the python documentation of subprocess, but that realy didn't help me at all, if anything, it confused me.

我注意到,我还需要在管理模式"下运行我的代码编辑器,以使其具有直接保存到所述目录中的plugin文件夹中的权限.似乎程序文件"文件夹中的文件受到某种保护.另外,此插件将安装在Mac或Windows的多台不同计算机上,因此,例如,不能选择对programm files文件夹进行更改权限.最后,只需拖放即可安装.

I noticed, that I also need to run my code editor in Admin Mode, in order for it to have permission to save directly into the plugin folder in said directory. It seems like files in the 'program files' folder are somehow protected. Also, this plugin will be installed on several different computers either mac or windows, and therefor changing permission on for example the programm files folder is not an option. In the end draging and droping should be all one has to do in order to install it.

有人知道如何实现吗?

推荐答案

您需要提升的权限才能在Windows上写入程序文件,但是您的插件不支持它们.我会考虑只使用另一个目录.

You need elevated permissions to write to Program Files on Windows, somehow your plugin does not have them. I would consider just using another directory.

许多渲染解决方案都要求您在某个位置指定目录,因此我认为这不是一个大问题.例如,模501和601(大概是701)需要一个目录进行数据共享.V-Ray for Maya或多或少要求您将场景文件以分布式模式放置在共享驱动器上.

Many render solutions requires you to specify a directory somewhere, so I don't think it's a huge problem. modo 501 and 601 (and 701 presumably), for example needs a directory somewhere for data sharing. V-Ray for Maya more or less requires you to put the scene files on a shared drive in distributed mode.

这篇关于python open()-拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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