系统: Window11
在激活已创建的环境时报如下错误:
表达式或语句中包含意外的标记“C:\Users\LingL\Desktop\scrcpy-win64-v2.6.1”。
所在位置 C:\Users\LingL\anaconda3\shell\condabin\Conda.psm1:76 字符: 9
PS C:\Users\LynL\Documents\_Programmes\Fed> conda activate fedml-py38
Invoke-Expression : 所在位置 行:1 字符: 1452
+ ... osoft VS Code\bin;"C:\Users\LynL\Desktop\scrcpy-win64-v2.6.1;";.;C:\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
表达式或语句中包含意外的标记“C:\Users\LynL\Desktop\scrcpy-win64-v2.6.1”。
所在位置 C:\Users\LynL\anaconda3\shell\condabin\Conda.psm1:76 字符: 9
+ Invoke-Expression -Command $activateCommand;
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : UnexpectedToken,Microsoft.PowerShell.Commands.InvokeExpressionCommand
解决方法:
在你所使用的PowerShell终端执行如下指令,规范终端的 PATH 环境变量格式。
# 移除多余的引号和空路径
$pathArray = ($env:PATH -split ';') | Where-Object { $_ -ne '' -and $_ -notmatch '^"$' }
# 去除多余引号
$cleanedPathArray = $pathArray | ForEach-Object { $_ -replace '"', '' }
# 重新拼接路径
$env:PATH = $cleanedPathArray -join ';'
然后正常激活conda环境即可。