【问题标题】:Why is my Python venv directory read-only?为什么我的 Python venv 目录是只读的?
【发布时间】:2021-04-25 00:39:47
【问题描述】:

我是 Python 中虚拟环境的新手。我在 Windows 10 上使用 Python 3.9 和管理员 Powershell 提示符(通过cmder)。

我创建了一个名为toto的新目录,将其设置为当前目录($ cd toto),然后运行以下命令:

$  python -m venv env

到目前为止一切顺利。但后来我想激活虚拟环境,使用以下命令:

$ .\env\Scripts\Activate.ps1

但似乎env 目录及其内容是只读的(Windows 文件系统表明如此),并且我收到以下错误(从法语翻译成英语不好):

+ 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

为什么会发生这种情况,以及如何解决这个问题?

【问题讨论】:

  • 尝试使用.\env\Scripts\activate看看是否同样的错误
  • @dfundako:同样的错误,很遗憾
  • 在您使用过cmder的问题中提及可能会有所帮助。

标签: python windows powershell readonly python-venv


【解决方案1】:

啊啊啊,我终于想通了。这个问题非常具体:这是由于我使用的终端是cmder(一个终端模拟器,它为默认窗口cmdpowershell 等添加了几个功能)。

问题在[here] 进行了讨论,修复似乎注释了cmder 配置文件中包含-Options ReadOnly 的行:cmder_path\vendor\profile.ps1

经过测试和批准,现在一切正常。

另一种解决方法也可能是不要将cmder 用于venv

【讨论】:

    猜你喜欢
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 2011-03-09
    • 2015-11-19
    • 2013-03-05
    • 2018-09-01
    • 2016-01-15
    • 2020-11-16
    相关资源
    最近更新 更多