I'm getting IOError: [Errno 13] Permission denied and I don't know what is wrong wit this code.
I'm trying to read a file given an absolute path
with open(r"E:\Paper\codedata.tsv", 'r+') as temp_f:
Error:
Traceback (most recent call last):
File "E:\Paper\code.py", line 18, in <module>
with open(r"E:\Paper\codedata.tsv", 'r') as temp_f:
What I have tried so far:
Changed file permissions. I am using Windows 10
Windows is upto Date
Working in Anaconda spyder. Tried opening spyder in admin and running the code
Changed directory of data to different path
I am using Python 3.
Related
Am I missing something here, I am attempting to make a directory then change CWD into that directory, however it keeps throwing an error saying "FileNotFoundError: [Errno 2] No such file or directory:". This only happens if I first remove the directory and start with no directory there, once its created the first time it works fine.
If I run the code twice it works, first time I get the error.
import os
def func_name_here():
os.popen('mkdir -p /tmp/tun')
os.chdir(r'/tmp/tun')
func_name_here()
This gives me...
Traceback (most recent call last):
File "test.py", line 9, in <module>
func_name_here()
File "test.py", line 6, in func_name_here
os.chdir(r'/tmp/tun')
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tun'
Hi everyone so I have some python code I am trying to run from my terminal (will not work in an IDE) to take a .mp3 file and classify the genre of the song based on the Spectrogram that we are using the librosa library plugin for. The code is from this gitHub: https://github.com/cetinsamet/music-genre-classification .When I use the command prompt specified by the gitHub user who created this app I get this error in my terminal:
(base) Nicos-MacBook-Pro:src nico$ python3 get_genre.py ../test.mp3
Traceback (most recent call last):
File "get_genre.py", line 61, in <module>
main(sys.argv[1:])
File "get_genre.py", line 30, in main
net.load_state_dict(torch.load(MODELPATH, map_location='cpu'))
File "/Users/nico/opt/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 419, in load
f = open(f, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: '../utils/net.pt'
Here is the command line specified: $ python3 get_genre.py ../test.mp3
The error message quite plainly tells you that the code depends on having a file ../utils/net.pt
I am trying to run a python file. But i got this error.
Traceback (most recent call last):
File "modeltraining.py", line 29, in <module>
sr,audio = read(source + path)
File "C:\Users\RAAM COMPUTERS\Anaconda3\lib\site-packages\scipy\io\wavfile.py", line 233, in read
fid = open(filename, 'rb')
PermissionError: [Errno 13] Permission denied: 'development_set/'
Run Spyder as administrator
Right click --> run as administrator
Or may be you can change the permissions of the directory you want to save to so that all users have read and write permissions.
After some time relaunching Anaconda and Spyder, I got an alert from Avast antivirus about protecting me from a malicious file, the one I was trying to create.
After allowing it, the "[Errno 13] Permission denied" error disappeared.
In my case, it seem the cause of the problem was Avast locking the directory.
numpy.save(array, path) worked fine, but PIL.Image().save(path) was blocked.
I am completely late to the party, but here is a tip for someone who tried everything and it didn't work.
In Spyder go to python->PYTHONPATH manager and add path to the folder with your data there.
Worked for me
I had the permission error when accessing a file on an external card. I guess the error has nothing to do with anaconda, that is just accidentally in the traceback.
Traceback (most recent call last):
File "C:\Users\Admin\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-219c041de52a>", line 105, in <module>
bs = open(filename, 'rb').read()
PermissionError: [Errno 13] Permission denied: 'D:\\[MYFILEPATH]\\test.bson'
I have checked this error in Spyder and PyCharm, it seems to be independent from the IDE. As the (Windows) solutions here (run as admin, add pythonpath) could not help me, my workaround was to copy the directory to my local disk and work from there.
Later I realised that it is obviously just the one file that is accessed ant that throws the permission that needs to be copied to your local disk, while you can use all your codework on externally.
Example:
Error. Get the permission error by accessing external drive "D:\":
filename = "D:\\test.bson"
# This throws the permission error
bs = open(filename, 'rb').read()
Solution. Avoid the permission error by accessing local drive "C:\":
filename = "C:\\Users\\Admin\\Documents\\test.bson"
# This throws no permission error
bs = open(filename, 'rb').read()
The whole code can now be saved on external "D:\test.py".
It might be the Windows Defender Firewall which was also mentioned when I installed PyCharm (and needed some automatic configurations which also did not solve the issue, but could be linked with it). It is clearly a problem of access rights, the firewall as the cause is quite plausible. Perhaps someone else finds out more about this.
I dont have much experience in python, so it might be a stupid question.
Im trying to write to a file in my script, if I run the script from his folder, it works, however if I run it from another folder, I have an error 13 persmission denied
i.e. in cmd :
cd C:\Users\user010\Perforce\Build\LS3\
py Build_jenkins.py
works but
cd C:\Program Files (x86)\Jenkins\workspace\LC3.3 Test\Qt\main
py C:\Users\user010\Perforce\Build\LS3\Build_jenkins.py
doesnt work. I have tried moving the script and the file to a public folder, same error :
Traceback (most recent call last):
File "C:\Users\Public\Documents\Build\LS3\Build_jenkins.py", line 159, in <module>
Variables.Sauvegarder()
File "C:/Users/Public/Documents/Build/LS3/../Common\Variables.py", line 87, in Sauvegarder
gArbre.write( NOM_FICHIER )
File "C:\Python34\lib\xml\etree\ElementTree.py", line 761, in write
with _get_writer(file_or_filename, encoding) as write:
File "C:\Python34\lib\contextlib.py", line 59, in __enter__
return next(self.gen)
File "C:\Python34\lib\xml\etree\ElementTree.py", line 798, in _get_writer
errors="xmlcharrefreplace")
PermissionError: [Errno 13] Permission denied: 'Variables.xml'
The code is Variables.Sauvegarder() in my main file and in Variables :
import xml.etree.ElementTree as ET
gArbre = ET.parse( "Variables.xml" )
def Sauvegarder():
gArbre.write( "Variables.xml")
Edit : important detail I forgot to mention, the file im writing to is located in the script folder (C:/Users/Public/Documents/Build/LS3/../Common\Variables.xml)
To be honest, I'm not sure about Windows computers (for a mac or other linux-based system you'd use sudo), but I would recommend trying to run the command as an administrator (use the runas command plus the name of an account with admin priveledges.) That should hopefully fix the error you're getting.
I am using IDLE on windows , when i run this below code i get error .
mut = 'F:\Perl\python\Examples'
file_name = open (mut,'r')
Traceback (most recent call last):
File "", line 1, in
file_name = open (mut,'r')
PermissionErroenter code herer: [Errno 13] Permission denied: 'F:\Perl\python\Examples'
'F:\Perl\python\Examples' is the path where my 'mut' file is located.
Please assists i am confused ?
'/' can be used on Windows quite happily, and is simpler.
Looks like Examples is a directory/folder - it should be a filename. That is why you are getting the error.
Note that open() returns a file handle, not a file name. What are you expecting this code to do?
Are you perhaps looking for os.walk() or os.listdir()?