安装pyenv
根据官方文档:
1.打开powershell并运行以下代码安装pyenv
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"
过程中可能出现无法访问资源的情况,这时候需要架个梯子
如提示禁止运行脚本,运行set-executionpolicy remotesigned后重试
2.重启powershell输入pyenv --version
查看是否安装成功,若成功则会出现版本号
打开环境变量发现,在线安装创建了三个用户变量:
PYENV
PYENV_HOME
PYENV_ROOT
以及两个路径:
C:\Users\Administrator.pyenv\pyenv-win\bin
C:\Users\Administrator.pyenv\pyenv-win\shims
也就是说,选择手动安装的话创建好这五个变量即可使用(maybe),如安装过python,可使用pip下载pyenv本地包:
pip install pyenv-win --target ‘目标文件位置’
本地包安装python
安装python的时候可能会发现安装包下载速度极慢,网速监测软件上面看只有100KB/s
PS C:\Users\Administrator> pyenv install 3.10.4
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Downloading] :: 3.10.4 …
:: [Downloading] :: From https://www.python.org/ftp/python/3.10.4/python-3.10.4-amd64.exe
:: [Downloading] :: To C:\Users\Administrator.pyenv\pyenv-win\install_cache\python-3.10.4-amd64.exe
根据提示信息可以知道安装包下载到install_cache这个位置
图中install_cache和shims都是运行之后自动创建的文件夹
接下来就很简单了,进入文件夹将安装包拖进去
再运行一次ps,发现识别到安装包开始自动安装了
PS C:\Users\Administrator> pyenv install 3.9.13
:: [Info] :: Mirror: https://www.python.org/ftp/python
:: [Installing] :: 3.9.13 …
:: [Info] :: completed! 3.9.13
接下来输入pyenv global 3.9.13
重启ps即可
注:若原来装过python可能需要清掉原python和pip的路径才能正常使用(系统变量比用户变量优先级更高)
以下是一些命令:
Usage: pyenv <command> [<args>]
Some useful pyenv commands are:
commands List all available pyenv commands
local Set or show the local application-specific Python version
global Set or show the global Python version
shell Set or show the shell-specific Python version
install Install a Python version using python-build
uninstall Uninstall a specific Python version
rehash Rehash pyenv shims (run this after installing executables
version Show the current Python version and its origin
versions List all Python versions available to pyenv
which Display the full path to an executable
whence List all Python versions that contain the given executable
See `pyenv help <command>' for information on a specific command.