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:~$
Related
I'm writing a Python script to make a backup of the photos on my tablet (Android 11) to an USB memory stick (FAT32). I run the script with Pydroid3. To make my question simple, I reduced to script to the minimum.
Here is the code:
import shutil
source = r'/storage/emulated/0/DCIM/Camera/img1.jpg'
target = r'/dev/bus/usb/001/002/Pics'
shutil.copyfile(source, target)
This results in the error:
PermissionError: [Errno 13] Permission denied: '/dev/bus/usb/001/002/Pics'
I found the target path with the app 'PyTool USB serial free'.
SolideExplorer gives another path: '/mnt/media_rw/C087-2599/Pics',
but this gives the same error.
How can I solve this problem? Do I need to give Pydroid3 permission?
But how? In the script itself?
Thanks for any help!
I would like to open a folder with Pycharm but I get an error every time I try ...
I just execute the command:
saves = open ("saves")
I've tried starting it as an administrator but it didn't work
I've tried changing the folder permissions and it didn't work either
I would like help thanks!
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.
I'm trying to open a script from the same directory with subprocesses with python 3 in Windows 10,(I Am the administrator) and using pycharm, however I'm getting the following errors for any alternative solution I try:
Here is my code:
import subprocess
subprocess.call(['C:\\Users\\CobraCommander\\PycharmProjects\\BlackBox', 'Avalon.py']) # The above "BlackBox" it's the directory for both files.
with this I get the following error:
PermissionError: [WinError 5] Access is denied
If I try instead:
subprocess.call(['python Avalon.py'])
with this I get the following error:
FileNotFoundError: [WinError 2] The system cannot find the file specified
so I tried:
subprocess.call(['C:\\Users\\CobraCommander\\PycharmProjects\\BlackBox\\Avalon.py'])
with this I get the following error:
OSError: [WinError 193] %1 is not a valid Win32 application
I also tried to run as administrator from terminal and get same error:
PermissionError: [WinError 5] Access is denied
Kindly before trying to mark as duplicate, note that I have already read the other posts for the errors as well as subprocesses.
Can anybody advise how to lunch this script in python from another script?
Add python before your script so instead of
subprocess.call(['C:\\Users\\CobraCommander\\PycharmProjects\\BlackBox\\Avalon.py'])
use
subprocess.call(['python', 'C:\\Users\\CobraCommander\\PycharmProjects\\BlackBox\\Avalon.py'])
Make sure your PYTHONPATH environment variable is set.
You need to supply cwd argument to set the working directory:
https://docs.python.org/3/library/subprocess.html#subprocess.call
import subprocess
if __name__ == '__main__':
subprocess.run(r'touch d:\test.txt')
p = subprocess.run(r'ls -la test.txt', cwd=r'd:\\', stdout=subprocess.PIPE)
print(p.stdout.decode())
output:
-rw-r--r-- 1 abdusco 197609 0 Jul 18 13:32 test.txt
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.