# "PermissionError: \[Errno 13\] Permission denied"in windows

**URL:** <https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571>\
**Category:** Python Help\
**Created:** [June 24, 2024, 3:40pm UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571 "2024-06-24T15:40:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![olivia\_olivia](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@olivia\_olivia](https://discuss.python.org/u/olivia_olivia)\
**Post date:** [June 24, 2024, 3:40pm UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/1 "2024-06-24T15:40:56Z")

</div>

I have already run anaconda as an administrator, but it still shows “PermissionError: [Errno 13] Permission denied”.  
I thought it was because the folder attribute is read-only, so i tried several ways to change this such as CMD checks and powershell checks but the folder still shows read-only. The windows support said that this was not the issue and the display of read-only is something can’t be changed.  
So what am i suppose to do next. Thanks.

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [June 24, 2024, 3:55pm UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/2 "2024-06-24T15:55:58Z")

</div>

What code are you executing to get this error?

---

<div class="post-metadata">

**Author:** ![olivia\_olivia](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@olivia\_olivia](https://discuss.python.org/u/olivia_olivia)\
**Post date:** [June 25, 2024, 6:57am UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/5 "2024-06-25T06:57:10Z")

</div>

```python
import sys
print(sys.executable)
import wave
import json
import os
import threading
import sounddevice as sd
from scipy.io.wavfile import write
import keyboard
from vosk import Model, KaldiRecognizer
import numpy as np

standard_text = "hello python hello world"

def record_audio(file_path):
    fs = 16000

    save_dir = os.path.dirname(file_path)
    if not os.path.exists(save_dir):
        os.makedirs(save_dir)
        print(f"Directory created: {save_dir}")
    else:
        print(f"Directory already exists: {save_dir}")

    recording = threading.Event()

    def on_press(key):
        nonlocal recording
        if key.name == 'esc':
            print("Start recording...")
            recording.set()
        elif key.name == 'enter':
            print("Stop recording...")
            recording.clear()

    keyboard.on_press(on_press)

    print("Press ESC key to start recording, press Enter key to stop...")
    recording.wait()

    frames = []

    def callback(indata, frames, time, status):
        frames.append(indata.copy())

    with sd.InputStream(samplerate=fs, channels=1, callback=callback):
        recording.wait()

    if len(frames) > 0:
        write(file_path, fs, np.concatenate(frames))
        print(f"File saved at: {file_path}")
    else:
        print("No audio frames recorded, recording failed!")

    keyboard.unhook_all()

def recognize_speech(file_path):
    if not os.path.exists("model"):
        print("Please download the model and place it in the current directory.")
        return ""

    wf = wave.open(file_path, "rb")
    if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getframerate() != 16000:
        print("Unsupported audio format")
        return ""

    model = Model("model")
    rec = KaldiRecognizer(model, wf.getframerate())
    rec.SetWords(True)

    results = []
    while True:
        data = wf.readframes(4000)
        if len(data) == 0:
            break
        if rec.AcceptWaveform(data):
            results.append(rec.Result())
        else:
            results.append(rec.PartialResult())
    results.append(rec.FinalResult())

    wf.close()

    text = ""
    for result in results:
        result_dict = json.loads(result)
        if 'text' in result_dict:
            text += result_dict['text'] + " "
    return text.strip()

def compare_texts(recorded_text, standard_text):
    differences = []
    recorded_tokens = recorded_text.split()
    standard_tokens = standard_text.split()
    for i in range(min(len(recorded_tokens), len(standard_tokens))):
        if recorded_tokens[i] != standard_tokens[i]:
            differences.append((i, recorded_tokens[i], standard_tokens[i]))
    return differences

def main():
    file_path = r"D:\Project\guben\record_save"
    record_audio(file_path)
    recorded_text = recognize_speech(file_path)
    print("Recorded text:", recorded_text)
    differences = compare_texts(recorded_text, standard_text)
    if differences:
        print("Detected differences:")
        for diff in differences:
            print(f"Position {diff[0] + 1}: Recorded text '{diff[1]}' differs from standard text '{diff[2]}'")
    else:
        print("Recorded text matches the standard text")

if __name__ == " __main__":
    main()

```

I’m new here and don’t know much about the format. If there is anything inappropriate, please let me know. Thank you.

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [June 25, 2024, 6:58am UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/6 "2024-06-25T06:58:28Z")

</div>

What is the full traceback? What are the relevant variables at that point in time?

---

<div class="post-metadata">

**Author:** ![olivia\_olivia](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@olivia\_olivia](https://discuss.python.org/u/olivia_olivia)\
**Post date:** [June 25, 2024, 7:00am UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/7 "2024-06-25T07:00:36Z")

</div>

Traceback (most recent call last):  
File “D:\Project\guben\yunxing2.py”, line 129, in   
main()  
File “D:\Project\guben\yunxing2.py”, line 118, in main  
recorded\_text = recognize\_speech(file\_path)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “D:\Project\guben\yunxing2.py”, line 75, in recognize\_speech  
wf = wave.open(file\_path, “rb”)  
^^^^^^^^^^^^^^^^^^^^^^^^^^  
File “D:\Anaconda\envs\myenv\Lib\wave.py”, line 649, in open  
return Wave\_read(f)  
^^^^^^^^^^^^  
File “D:\Anaconda\envs\myenv\Lib\wave.py”, line 282, in **init**  
f = builtins.open(f, ‘rb’)  
^^^^^^^^^^^^^^^^^^^^^^  
PermissionError: [Errno 13] Permission denied: ‘D:\Project\guben\record\_save’

---

<div class="post-metadata">

**Author:** ![MegaIng](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/megaing/32/16162_2.png) [@MegaIng](https://discuss.python.org/u/MegaIng)\
**Post date:** [June 25, 2024, 7:03am UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/8 "2024-06-25T07:03:07Z")

</div>

So the problem or that you are trying to open a folder as it is were a file, which didn’t work. On windows this produces a Permission Error instead of something more helpful.

---

<div class="post-metadata">

**Author:** ![olivia\_olivia](https://avatars.discourse-cdn.com/v4/letter/o/7ba0ec/32.png) [@olivia\_olivia](https://discuss.python.org/u/olivia_olivia)\
**Post date:** [June 25, 2024, 7:06am UTC](https://discuss.python.org/t/permissionerror-errno-13-permission-denied-in-windows/56571/9 "2024-06-25T07:06:57Z")

</div>

😮 I will try, thanks
