Search code examples
pythonwindowspowershellreadonlypython-venv

Why is my Python venv directory read-only?


I am new to virtual envs in Python. I am using Python 3.9 on Windows 10, and an admin Powershell prompt (through cmder).

I created a new directory named toto, set it as current directry ($ cd toto), and ran the following command :

$  python -m venv env

So far so good. But then I want to activate the virtual environment, using the following command :

$ .\env\Scripts\Activate.ps1

But it seems that the env directory and its content is read-only (Windows file system indicates so), and I get the following error (poorly translated from french to english) :

+ CategoryInfo          : WriteError: (prompt:String) [Copy-Item], SessionStateUnauthorizedAccessException
+ FullyQualifiedErrorId : FunctionNotWritable,Microsoft.PowerShell.Commands.CopyItemCommand

Impossible to write in the prompt fonction, because it is constant or read-only.
At character D:\outils\PyperGraph\env\Scripts\Activate.ps1:227 : 5
+     function global:prompt {
+     ~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : WriteError: (prompt:String) [], SessionStateUnauthorizedAccessException
      + FullyQualifiedErrorId : FunctionNotWritable

Why is this happening, and how to fix this issue ?


Solution

  • Aaaaand I enventually figured it out. The issue was quite specific : it is due to the terminal I use, which is cmder (a terminal emulator which adds several fonctionnalities to the defaults windows cmd, powershell and others).

    Issue is discussed [here], and the fix appears to comment the line which contains -Options ReadOnly in the cmder profile file: cmder_path\vendor\profile.ps1.

    Tested and approved, everything works fine now.

    Another workaround could also be not to use cmder for venv.