How to overcome from the permission error? - python

How to overcome from the permission error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Ramesh\AppData\Local\Programs\Python\Python39\lib\site-packages\playsound.py", line 41, in _playsoundWin
copy(sound, tempPath)
File "C:\Users\Ramesh\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 418, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Ramesh\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'F:\\Python course\\1. Chapter 1'

Can you post the code? If you do it I will be able to check the error more clearly and answer your question nad you also check if there are any errors

Related

Compile Cython Extensions Error - Pycharm IDE. Linux Mint

Non-zero exit code (1):
Traceback (most recent call last):
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 242, in main()
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 233, in main with FrameEvalModuleBuildContext():
File "/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/setup_cython.py", line 187, in __enter__ shutil.copy(compatible_c, self._c_file)
File "/usr/lib/python3.9/shutil.py", line 427, in copy copyfile(src, dst, follow_symlinks=follow_symlinks)
File "/usr/lib/python3.9/shutil.py", line 266, in copyfile with
open(dst, 'wb') as fdst: OSError: [Errno 30] Read-only file system: '/snap/pycharm-community/315/plugins/python-ce/helpers/pydev/_pydevd_frame_eval/pydevd_frame_evaluator.c'
I did as written here, but it doesn't work yet.
Please tell me what else can be done.

the Error is: PermissionError: [Errno 13] Permission denied: 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\IP.PY'

This is my code:
import shutil
original = r'C:\Users\Руслан\Desktop\HACKPROG\IP.PY'
target = r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp'
shutil.move(original,target)
and I am getting the following Error:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\Руслан\Desktop\HACKPROG\IP.PY", line 24, in <module>
shutil.move(original,target)
File "C:\Users\Руслан\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 820, in move
copy_function(src, real_dst)
File "C:\Users\Руслан\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 435, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Руслан\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp\\IP.PY'
You don't appear to have permissions to write to the Start Up folder.
You can fix this by running your Python terminal as an administrator (right click IDLE/cmd and press run as administrator).
you can run this program in 2 ways
Method 1:
Add python to path, By editing environmental variables.
Method 2:
Open console/cmd . Direct path to python file by
cd C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\StartUp
And then after entering directory
python ip.py --user

Permission denied by shutil.copy() when copying a directory instead of a file

This is the code I executed:
shutil.copy(r'd:\try',r'd:\new')
The output I got was:
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
shutil.copy(r'd:\try',r'd:\new')
File "C:\Users\Username\AppData\Local\Programs\Python\Python38-32\lib\shutil.py", line 415, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\shutil.py", line 261, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'd:\\try'
I get this permission error only when I try to copy folders but this error doesn't occur when I copy a file. How to fix this?
As can be read in the documentation, shutil.copy() is used for copying files.
To copy a directory, use shutil.copytree() instead:
shutil.copytree(r'd:\try', r'd:\new')

PermissionError: [WinError 5] Access is denied: Couldn't able to copy file to C:\Windows\System32\oobe\Info\backgrounds\

import os
import shutil
dir_src='D:\\'
dir_dst='C:\\Windows\\System32\\oobe\\Info\\backgrounds\\'
src_file=os.path.join(dir_src,'background.jpg')
dst_file=os.path.join(dir_dst,'backgroundefault.jpg')
print(os.path.join(dir_dst,'backgroundefault.jpg'))
shutil.move(src_file,dst_file)
I've been trying to copy a file to C:\Windows\System32\oobe\Info\backgrounds but I am getting this error:
Traceback (most recent call last):
C:\Windows\System32\oobe\Info\backgrounds\backgroundefault.jpg
File "C:\python\python36\lib\shutil.py", line 544, in move
os.rename(src, real_dst)
PermissionError: [WinError 5] Access is denied: 'D:\\background.jpg' -> 'C:\\Windows\\System32\\oobe\\Info\\backgrounds\\backgroundefault.jpg'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Harish/Downloads/demo (1).py", line 9, in <module>
shutil.move(src_file,dst_file)
File "C:\python\python36\lib\shutil.py", line 558, in move
copy_function(src, real_dst)
File "C:\python\python36\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\python\python36\lib\shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\oobe\\Info\\backgrounds\\backgroundefault.jpg'
How can I resolve it?

Shelve Module Not Working

After I reinstalled Python to move it from an AppData folder to Program Files, it looks like the shelve module is no longer working and I receive the error below when I call upon shelve.open().
Please help!
>>> import shelve
>>> myShelf = shelve.open('data')
Traceback (most recent call last):
File "C:\Program Files\Python\lib\dbm\dumb.py", line 81, in _create
f = _io.open(self._datfile, 'r', encoding="Latin-1")
FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
myShelf = shelve.open('data')
File "C:\Program Files\Python\lib\shelve.py", line 243, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "C:\Program Files\Python\lib\shelve.py", line 227, in __init__
Shelf.__init__(self, dbm.open(filename, flag), protocol, writeback)
File "C:\Program Files\Python\lib\dbm\__init__.py", line 94, in open
return mod.open(file, flag, mode)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 303, in open
return _Database(file, mode, flag=flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 69, in __init__
self._create(flag)
File "C:\Program Files\Python\lib\dbm\dumb.py", line 83, in _create
with _io.open(self._datfile, 'w', encoding="Latin-1") as f:
PermissionError: [Errno 13] Permission denied: 'data.dat'
>>>
The error "FileNotFoundError: [Errno 2] No such file or directory: 'data.dat'" shows you, it can not find the data.dat, please check the file location.
I had this problem using Windows 10. I solved the issue by changing the working directory to a folder under my profile.
os.chdir('C:\\Users\\Nat\\Documents\\Python\\Project 1')
I presume I didn't have permission to write a file 'Program Files'.

Categories

Resources