首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >pyenv窗口术语'pyenv‘不被识别为cmdlet函数的名称。

pyenv窗口术语'pyenv‘不被识别为cmdlet函数的名称。
EN

Stack Overflow用户
提问于 2022-10-06 13:37:05
回答 1查看 167关注 0票数 1

在vs代码中在powershell脚本中执行以下操作

代码语言:javascript
复制
& pip install pyenv-win --target "$HOME\.pyenv"
[System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
[System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User")
[System.Environment]::SetEnvironmentVariable('path', $HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"User")
& pyenv --version

获取错误术语'pyenv‘不能识别为cmdlet、函数、脚本文件或可操作程序的名称。

它第一次起作用了,但现在不再起作用了,这很奇怪(可能是与缓存有关)。对做错了什么有什么想法吗?

终端输出

代码语言:javascript
复制
collecting pyenv-win
  Using cached pyenv_win-3.1.1-py3-none-any.whl (3.6 MB)
Installing collected packages: pyenv-win
Successfully installed pyenv-win-3.1.1
WARNING: Target directory C:\Users\name\.pyenv\.version already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Users\name\.pyenv\pyenv-win already exists. Specify --upgrade to force replacement.
WARNING: Target directory C:\Users\name\.pyenv\pyenv_win-3.1.1.dist-info already exists. Specify --upgrade to force replacement.
& : The term 'pyenv' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\name\Source\Repos\LoadData\install_pyenv.ps1:6 char:3
+ & pyenv --version
+   ~~~~~
    + CategoryInfo          : ObjectNotFound: (pyenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-06 20:17:45

您正在修改注册表(值pathHKCU\Environment下),而不是修改当前进程($env:Path)的环境变量path

阅读Environment.SetEnvironmentVariable Method (引用被截断,我强调的重要部分):

超载:

SetEnvironmentVariable(String, String)

创建、修改或删除当前进程中存储的环境变量。…

SetEnvironmentVariable(String, String, EnvironmentVariableTarget)

创建、修改或删除存储在当前进程或操作系统注册表项中的环境变量,该注册表项为当前用户或本地计算机保留。…

而且,您的SetEnvironmentVariable('path', …, "User")将值"$SomePath;"+"$env:Path"存储到注册表(用户路径)。这意味着用户路径值现在包含当前$env:Path的用户部分和系统部分。您的用户路径值会恶化,同时考虑到$env:Path是按照以下方式构造的:

代码语言:javascript
复制
# if auxiliary variables `$systPath` and `$userPath` are as follows
$systPath = (Get-Item 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\').GetValue('Path').TrimEnd(';')
$userPath = (Get-Item 'HKCU:\Environment\').GetValue('Path').TrimEnd(';')
# then
$env:path -eq ($systPath, $userPath -join ';')
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73974811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档