Python版本管理器之Pyenv-win介绍与安装
Python版本管理器之Pyenv-win介绍与安装
文章目录
1. Pyenv-win
1. 官网
https://pyenv-win.github.io/pyenv-win/#introduction
github:https://github.com/pyenv-win/pyenv-win
2.Pyenv
gitHub: https://github.com/pyenv/pyenv
Pyenv for Python 是一个很棒的工具,但与 Ruby 开发的 rbenv 一样,它不直接支持 Windows。经过一些研究和 python 开发人员的反馈,我发现他们希望为 Windows 系统提供类似的功能。
3. pyenv-win是什么?
pyenv 的 Windows 版本。Pyenv 是一个简单的 Python 版本管理工具。它使您可以轻松地在多个 Python 版本之间切换。它简单、不引人注目,并遵循 UNIX 的传统,即只做一件事的单一用途工具。
该项目是从 rbenv-win 分叉出来的,并针对 pyenv 进行了修改。
2. 安装
1. 快速安装
-
在 PowerShell 中安装 pyenv-win。
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"
注意:执行此脚本可能会出现PowerShello的执行策略级别与执行脚本错误问题,详见
5. 安装时Powershell禁止运行脚本
-
重新打开 PowerShell
-
运行 以检查安装是否成功。
pyenv --version
-
运行 以查看 pyenv-win 支持的 Python 版本列表
pyenv install -l
-
运行以安装支持的版本
pyenv install <version>
-
运行以将 Python 版本设置为全局版本
pyenv global <version>
-
检查您正在使用的 Python 版本及其路径
> pyenv version <version> (set by \path\to\.pyenv\pyenv-win\.python-version)
如下图
- 检查 Python 是否正常工作
> python -c "import sys; print(sys.executable)"
\path\to\.pyenv\pyenv-win\versions\<version>\python.exe
如下图
2. pyenv-win 命令
commands List all available pyenv commands
local Set or show the local application-specific Python version
latest Print the latest installed or known version with the given prefix
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install 1 or more versions of Python
uninstall Uninstall 1 or more versions of Python
update Update the cached version DB
rehash Rehash pyenv shims (run this after switching Python versions)
vname Show the current Python version
version Show the current Python version and its origin
version-name Show the current Python version
versions List all Python versions available to pyenv
exec Runs an executable by first preparing PATH so that the selected
Python version's `bin' directory is at the front
which Display the full path to an executable
whence List all Python versions that contain the given executable
3. 用法
要查看 pyenv 窗口支持的 python 版本列表:pyenv install -l
要筛选列表,请执行以下作:pyenv install -l | findstr 3.8
要安装 python 版本:
pyenv install 3.11.9
pyenv install 2.4.3 3.6.8
在这里插入图片描述
要将 python 版本设置为全局版本,请执行以下作:
pyenv global 3.11.9
要将 python 版本设置为本地版本:。
pyenv local 3.11.9
python
使用 pip 安装(取消)安装任何库或修改版本文件夹中的文件后,必须运行以使用 python 和库可执行文件的新填充码更新 pyenv。
pyenv rehash
.pyenv
文件夹之外运行。要卸载 Python 版本:pyenv uninstall 3.11.9
要查看您正在使用的 Python 及其路径:pyenv version
pyenv versions
使用以下命令更新可发现的 Python 版本列表:pyenv-win 的命令和版本pyenv update``2.64.x``2.32
4. 更新 pyenv
easy_install.pth
pip install --upgrade pyenv-win
%USERPROFILE%\.pyenv\pyenv-win``git pull
%USERPROFILE%\.pyenv\pyenv-win``libexec``bin
&"${env:PYENV_HOME}\install-pyenv-win.ps1"
5. 安装时Powershell禁止运行脚本
1. 安装pyenv-win出差
2. 解决方式
原因是Windows新的权限执行策略改变,休要在PowerShell里面执行命令:
Get-ExecutionPolicy
# 输出的是:Restricted
若要更改执行策略,以管理员身份打开PowerShell,然后使用以下命令之一设置执行策略
Set-ExecutionPolicy RemoteSigned
具体提如下图
6.关于PowerShell运行脚本的方法
在Windows操作系统中,PowerShell默认的执行策略可能会限制用户运行脚本,这是一种安全措施,用于防止未经授权的脚本执行,可能对系统造成潜在的安全风险。如果用户确信要运行的脚本是安全的,可以通过更改执行策略来允许脚本执行。
更改执行策略的步骤
首先,需要了解PowerShell中的执行策略级别。执行策略有几种级别,包括:
要查看当前的执行策略,可以在PowerShell中输入以下命令:
Get-ExecutionPolicy
若要更改执行策略,以管理员身份打开PowerShell,然后使用以下命令之一设置执行策略:
Set-ExecutionPolicy RemoteSigned
或者,如果需要,也可以选择Unrestricted策略,但请注意这样做可能会增加安全风险:
Set-ExecutionPolicy Unrestricted
执行以上命令时,系统会提示确认更改。输入Y并回车以确认。
更改执行策略可能会影响系统的安全性。在更改执行策略之前,请确保了解可能的安全影响。如果在组织中使用PowerShell,可能需要咨询IT部门,因为组织可能有自己的安全策略。
作者:小猿搬码