• Windows上安装pyenv,以及pyenv切换环境不生效的问题


    1. pyenv安装

    重装了系统,之前的系统卡死了。

    于是也重装了pyenv, 在官网上看到有powershell命令一键安装:

    Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
    
    • 1

    但是等了半天也没有下载成功,国内网络环境棒棒哒。
    看到gitee上有克隆项目,于是将链接同步使用国内的。

    https://gitcode.com/mirrors%2Fpyenv-win/pyenv-win/blob/master/pyenv-win%2Finstall-pyenv-win.ps1
    
    • 1

    将上面脚本链接换为下面的,这次可以成功下载了,但是实际安装提示脚本错误.

    PS C:\Users\Miste> Invoke-WebRequest -UseBasicParsing -Uri "https://gitcode.com/mirrors%2Fpyenv-win/pyenv-win/tree/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
    所在位置 C:\Users\Miste\install-pyenv-win.ps1:7 字符: 10
    +     <!-- "referrer" content="no-referrer"> -->
    +          ~
    “<”运算符是为将来使用而保留的。
        + CategoryInfo          : ParserError: (:) [], ParseException
        + FullyQualifiedErrorId : RedirectionNotSupported
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    仔细看看下载的文件,里面居然是html,是TM一个网页文件。
    所以只能强行去复制代码了(浏览器打开链接并复制源码到本地)
    然后再使用powershell执行脚本,至此,安装完成。

    2. pyenv使用

    安装完成了,首先安装个python版本,执行:

    pyenv install 3.11.4
    
    • 1

    安装完成后设置为全局使用:

    pyenv global 3.11.4
    
    • 1

    然后重新打开cmd窗口,查看python版本:

    C:\Users\Miste>python -V
    Python 2.7.18
    
    C:\Users\Miste>
    
    • 1
    • 2
    • 3
    • 4

    居然没生效,于是又设置了几次,但是还是没有生效。MD
    网上找找资料,最后看到一段话:

    In windows NT, the PATH variable is a combined result of the system and user variables:

    The Path is constructed from the system path, which can be viewed in the System Environment Variables field in the System dialog box. The User path is appended to the system path

    Shims PATH are defined in the user variables, so make sure your host python interpreter path is not defined in your system path

    意思是windows环境变量中有配置的python版本,则pyenv将不生效。所以我去看了下

    右键我的电脑>属性>高级系统设置>环境变量

    这里检查下有没有自己定义python路径,有的话删除掉,我这里就是这里有定义一个2.7.18的,删除掉后就好了。

  • 相关阅读:
    模拟一个火车站售票小例子
    Python进阶学习----一闭三器
    【Linux】线程安全-死锁
    电脑进水无法开机怎么办 电脑进水开不了机的解决方法
    nginx 访问静态文件404错误
    讲一讲VS Code配置GoLang语言开发环境
    C语言中typedef和define对比分析
    redux和Vuex的使用示例
    【代码随想录】Day 50 动态规划11 (买卖股票Ⅲ、Ⅳ)
    mysql实现删除某一列的重复数据(只留一行或全部删除)
  • 原文地址:https://blog.csdn.net/jioulongzi/article/details/133880310