PermissionError: [WinError 5] python 使用moviepy 写gif 被拒绝访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26091530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PermissionError: [WinError 5] Access is denied python using moviepy to write gif
提问by Abirafdi Raditya Putra
I'm using windows 8.1 64 bit
我使用的是 Windows 8.1 64 位
my code
我的代码
import pdb
from moviepy.editor import *
clip = VideoFileClip(".\a.mp4")
clip.write_gif('.\aasda.gif')
the exception is at write_gif method
例外是在 write_gif 方法
Traceback (most recent call last):
File "C:\abi\youtubetogif_project\test.py", line 5, in <module>
clip.write_gif('G:\abi\aasda.gif')
File "<string>", line 2, in write_gif
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\decorators.py", line 49, in requires_duration
return f(clip, *a, **k)
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\video\VideoClip.py", line 435, in write_gif
dispose= dispose, colors=colors)
File "<string>", line 2, in write_gif
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\decorators.py", line 49, in requires_duration
return f(clip, *a, **k)
File "C:\Python34\lib\site-packages\moviepy-0.2.1.8.12-py3.4.egg\moviepy\video\io\gif_writers.py", line 186, in write_gif
stdout=sp.PIPE)
File "C:\Python34\lib\subprocess.py", line 848, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1104, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
I moved the script to another folder and partition, running moviepy dependancies and python as admin, turning off UAC still gives me error
我将脚本移动到另一个文件夹和分区,以管理员身份运行 moviepy 依赖项和 python,关闭 UAC 仍然给我错误
回答by Reed Jones
I've run into this as well, solution is usually to be sure to run the program as an administrator (right click, run as administrator.)
我也遇到过这种情况,解决方案通常是确保以管理员身份运行程序(右键单击,以管理员身份运行。)
回答by Marco smdm
Maybe you wrongly set permission on python3. For instance if for the file permission is set like
也许你错误地设置了 python3 的权限。例如,如果文件权限设置为
`os.chmod('spam.txt', 0777)` --> This will lead to SyntaxError
This syntax was used in Python2. Now if you change like:
os.chmod('spam.txt', 777)--> This is still worst!! Your permission will be set wrongly since are not on "octal" but on decimal.
这个语法在 Python2 中使用过。现在,如果您更改为:
os.chmod('spam.txt', 777)--> 这仍然是最糟糕的!!您的权限将被错误设置,因为不是“八进制”而是十进制。
Afterwards you will get permission Error if you try for instance to remove the file: PermissionError: [WinError 5] Access is denied:
之后,如果您尝试删除文件,您将获得权限错误:PermissionError: [WinError 5] Access is denied:
Solution for python3 is quite easy:
os.chmod('spam.txt', 0o777)--> The syntax is now ZERO and o "0o"
python3的解决方案很简单:
os.chmod('spam.txt', 0o777)-->语法现在是零和o“0o”
回答by OuuLin
Sometimes it occurs when some installations are not completed correctly, the process is stuck, or a file is still opened. So, when you try to run the installation again and the installation requires deleting, you can see the aforementioned error. In my case, shutting down the python processes and command prompt utilization helped.
有时在某些安装未正确完成、进程卡住或仍然打开文件时会发生这种情况。因此,当您再次尝试运行安装并且安装需要删除时,您会看到上述错误。就我而言,关闭 python 进程和命令提示符使用有所帮助。
回答by tomalf2
I got the same error when an imported library was trying to create a directory at path "./logs/".
当导入的库尝试在路径“./logs/”处创建目录时,我遇到了同样的错误。
It turns out that the library was trying to create it at the wrong location, i.e. inside the folder of my python interpreter instead of the base project directory. I solved the issue by setting the "Working directory" path to my project folder inside the "Run Configurations" menu of PyCharm. If instead you're using the terminal to run your code, maybe you just need to move inside the project folder before running it.
事实证明,该库试图在错误的位置创建它,即在我的 python 解释器的文件夹中,而不是在基本项目目录中。我通过在 PyCharm 的“运行配置”菜单中将“工作目录”路径设置为我的项目文件夹解决了这个问题。相反,如果您使用终端来运行您的代码,也许您只需要在运行之前移动到项目文件夹中即可。

