I was trying to copy file from my desktop to System32 dir. it give me the following error.
PermissionError: [Errno 13] Permission denied:'C:/Windows/System32/abc.exe'
here is my code
src = pth + "\\" +s_name
dist = "C:/Windows/System32/"
shutil.copy(src , dist)
The issue is not with Python or shutil. Permission denied means that the user that runs the Python script does not have a permission to copy the file to C:/Windows/System32.
I think what you could do now is to look for a way to run the script as Windows administrator.
Related
Basically I have a python script which is "converted" to exe, located in C:\Users\USER_NAME\AppData\Roaming\Folder. When started manually (not as admin), the script can write to file (file is located in the same directory as the script). But when the script runs on startup (I added a registry string to Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run with an executable path as data) I get Permission Denied error, why is that so and how could I fix it?. Code for opening file:
file = open(os.path.join(current_path, "text.txt"), "a+")
Error:
PermissionError: [Errno 13] Permission denied: '.\\text.txt'
The issue was that the script was run from C:\Windows\System32 not from C:\Users\USER_NAME\AppData\Roaming\Folder (windows being weird I guess)
I have a mac computer and am trying to use the basic copy or move functions from the Shutil library.
Whenever I run the code, the console prints an error:
PermissionError: [Errno 1] Operation not permitted: '/Users/ryanyee/Desktop/scr/CC_Info - Alex - 8'
or something similar to that error.
Here is my code below:
import shutil, os
source = "/Users/ryanyee/Desktop/scr/CC_Info - Alex - 8"
destination = "/Users/ryanyee/Desktop/dest"
shutil.copy(source,destination)
The code should copy that single file from the scr folder to the dest folder.
I have tried to change the directory and print the directory using:
os.chdir('/Users/ryanyee/Desktop/scr')
print(os.getcwd())
This is the error I get when I use that:
PermissionError: [Errno 1] Operation not permitted
The issue was that my current working directory was saving the documents to the same folder that my code was stored.
To fix the code, I had to have the document in the same folder that the script was saved in.
Python 2.7
Windows 8
I downloaded a file from the internet using:
testfile = urllib.URLopener()
testfile.retrieve(str(audio_link), "audio.mp3")
audio_link is a format something like:
http://static.sfdict.com/staticrep/dictaudio/R02/R0203700.mp3
The program should be writing to an existing audio.mp3 in the working directory with the url from the above code. It was working properly until I made some changes to the program that don't seem to have to do with the problem.
Specifically, the problem shows:
File "D:\Paul\projects\spelling test\python.py", line 105, in get_pronunciation
testfile.retrieve(str(audio_link), "audio.mp3")#open the link as a saved file; creates file; maybe overwrites old??
File "C:\Python27\lib\urllib.py", line 249, in retrieve
tfp = open(filename, 'wb')
IOError: [Errno 13] Permission denied: 'audio.mp3'
get_pronunciation is a function, and I think that tfp is built in to the testfile usage.
My cmd has no chmod (I tried chmod 777 /working/directory/blah/) and, even as administrator, it is not recognized as a command.
I also tried to go to the properties of the working directory through windows explorer>right-click>properties>security tab>edit>click on Users>check-mark full control.
Help? Regards.
When I am trying to os.makedirs("/home/user/newdir"), while python script is located "/home/user/somefolder" it gives me
OSError: [Errno 13] Permission denied: '/home/user'
So how can I make newdir
The problem was that I used socket.gethostname() to get the user name of my pc, but I should have used getpass.getuser() instead. The getpass.gethostname() gave me "chriss", while in kristians#chriss:~$
I am trying to move a folder from one place to another, however I get this error when I try:
PermissionError: [Errno 13] Permission denied
I use the following code:
import os.path, shutil #, zipfile
if os.path.exists("\\\BOGORODITSASERV\\Not.py Files"):
print("#YOLO")
#zip command
shutil.copy2('C:\\Users\\Grant\\Documents\\AllDerProgramming','\\\BOGORODITSASERV\\Not.py Files')
#unzip command
print("Success!")
EDIT: I have made sure that the file is not open/being used. So to get around this error I was thinking zipping and unzipping the file would work.
EDIT:How then, if not by zipping, do I get rid if this error? Can I give python permission to this file path?
EDIT:I run this program on an admin account, I even run the shell as administrator and I still get the permission error.