1

I try to write a file with python on Windows 10. The command works when I use the python 3.7 installed outside any environment, but not when I use a python 3.7 installed inside a conda environment. The following error occurs :

Traceback (most recent call last):
File "foo.py", line 1, in <module>
with open("foo.txt", "w") as f:
    PermissionError: [Errno 13] Permission denied: 'foo.txt'

This works :

py foo.py

This raises the PermissionError :

conda create --name myenv python=3.7
conda activate myenv
python foo.py
# foo.py
with open("foo.txt", "w") as f:
    pass

The python location is C:\Users\myusername\miniconda3\envs\myenv\python.exe for the python inside the conda environment and C:\Windows\py.exe for the other one.
The current user is an administrator. I already tried to run the Anaconda prompt as administrator, and also to give full permission to Everyone for the current folder. I don't understand why it does not work.

Edit

I am actually able to run the script using the shortcut method explained here but I would prefer to find a solution that does not require me to create a shortcut for each script I write in my conda environments.

Karexar
  • 11
  • 2
  • Hello, where is the `foo.txt` placed? [Here](https://stackoverflow.com/questions/36434764/permissionerror-errno-13-permission-denied/36469464) is solution to something like your problem. – Tony Apr 14 '21 at 17:09
  • `foo.txt` does not exist yet, it will be in the same directory as the script. Indeed the shortcut method from the link you mentioned works, but I would prefer to avoid having to create shortcuts for each script I write if there is another way – Karexar Apr 14 '21 at 20:26
  • @Karexar Your answer has some formatting problems. Try to improve that. Use `\`` brackets for paths and code fragments. To start from a new line use *double space* at the end of the line - the question'll be way more clear than using `Enter` everywhere. – maciejwww Apr 15 '21 at 01:47

0 Answers0