这是用户在 2024-6-7 16:13 为 https://github.com/pyenv-win/pyenv-win/blob/master/README.md 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
Skip to content
238 lines (180 loc) · 10.2 KB
·

README.md 自述文件.md

File metadata and controls

238 lines (180 loc) · 10.2 KB
·

pyenv for Windows 适用于 Windows 的 pyenv

pyenv is an amazing tool used to manage multiple versions of python in your machine. We have ported it to Windows. We need your thoughts to improve this library and your feedback helps to grow the project.
pyenv 是一个很棒的工具,用于管理计算机中多个版本的 python。我们已将其移植到Windows。我们需要您的想法来改进这个库,您的反馈有助于发展该项目。

For existing python users, we support installation via pip.
对于现有的 python 用户,我们支持通过 pip 安装。

Contributors and Interested people can join us on @Slack. Your help keeps us motivated!
贡献者和感兴趣的人可以通过@Slack 加入我们。您的帮助是我们前进的动力!

pytest License: MIT GitHub issues open Downloads Rate this package

Introduction 介绍

pyenv for python is a great tool but, like rbenv for ruby developers, it doesn't directly support Windows. After a bit of research and feedback from python developers, I discovered they wanted a similar feature for Windows systems.
用于 python 的 pyenv 是一个很棒的工具,但与用于 ruby​​ 开发人员的 rbenv 一样,它不直接支持 Windows。经过一些研究和 Python 开发人员的反馈后,我发现他们想要为 Windows 系统提供类似的功能。

This project was forked from rbenv-win and modified for pyenv. It is now fairly mature, thanks to help from many different contributors.
该项目是从 rbenv-win 分叉出来的,并针对 pyenv 进行了修改。由于许多不同贡献者的帮助,它现在已经相当成熟。

pyenv

pyenv is a simple python version management tool. It lets you easily switch between multiple versions of Python. It's simple, unobtrusive, and follows the UNIX tradition of single-purpose tools that do one thing well.
pyenv是一个简单的python版本管理工具。它可以让你轻松地在多个版本的 Python 之间切换。它简单、不引人注目,并且遵循 UNIX 的单一用途工具只做好一件事的传统。

Quick start 快速开始

  1. Install pyenv-win in PowerShell.
    在 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"
  2. Reopen PowerShell 重新打开 PowerShell

  3. Run pyenv --version to check if the installation was successful.
    运行 pyenv --version 检查安装是否成功。

  4. Run pyenv install -l to check a list of Python versions supported by pyenv-win
    运行 pyenv install -l 查看 pyenv-win 支持的 Python 版本列表

  5. Run pyenv install <version> to install the supported version
    运行 pyenv install <version> 安装支持的版本

  6. Run pyenv global <version> to set a Python version as the global version
    运行 pyenv global <version> 将Python版本设置为全局版本

  7. Check which Python version you are using and its path
    检查您正在使用的Python版本及其路径

    > pyenv version
    <version> (set by \path\to\.pyenv\pyenv-win\.python-version)
    
  8. Check that Python is working
    检查 Python 是否正常工作

    > python -c "import sys; print(sys.executable)"
    \path\to\.pyenv\pyenv-win\versions\<version>\python.exe
    

pyenv-win commands 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

Installation 安装

Currently we support following ways, choose any of your comfort:
目前我们支持以下方式,您可以选择任意一种:

Please see the Installation page for more details.
请参阅安装页面了解更多详细信息。

Validate installation 验证安装

  1. Reopen the command prompt and run pyenv --version
    重新打开命令提示符并运行 pyenv --version
  2. Now type pyenv to view it's usage
    现在输入 pyenv 查看它的用法

If you are getting "command not found" error, check the below note and manually check the settings
如果您收到“找不到命令”错误,请检查以下注释并手动检查设置

For Visual Studio Code or another IDE with a built in terminal, restart it and check again
对于 Visual Studio Code 或其他具有内置终端的 IDE,请重新启动并再次检查


Manually check the settings
手动检查设置

Ensure all environment variables are properly set with high priority via the GUI:
确保通过 GUI 以高优先级正确设置所有环境变量:

This PC
   → Properties
      → Advanced system settings
         → Advanced → Environment Variables...
            → PATH

NOTE: If you are running Windows 10 1905 or newer, you might need to disable the built-in Python launcher via Start > "Manage App Execution Aliases" and turning off the "App Installer" aliases for Python
注意:如果您运行的是 Windows 10 1905 或更高版本,您可能需要通过“开始”>“管理应用程序执行别名”禁用内置 Python 启动器,并关闭 Python 的“应用程序安装程序”别名

Usage 用法

  • To view a list of python versions supported by pyenv windows: pyenv install -l
    查看 pyenv windows 支持的 python 版本列表: pyenv install -l
  • To filter the list: pyenv install -l | findstr 3.8
    过滤列表: pyenv install -l | findstr 3.8
  • To install a python version: pyenv install 3.5.2
    要安装 python 版本: pyenv install 3.5.2
    • Note: An install wizard may pop up for some non-silent installs. You'll need to click through the wizard during installation. There's no need to change any options in it. or you can use -q for quiet installation
      注意:对于某些非静默安装,可能会弹出安装向导。您需要在安装过程中单击向导。无需更改其中的任何选项。或者您可以使用 -q 进行安静安装
    • You can also install multiple versions in one command too: pyenv install 2.4.3 3.6.8
      您也可以在一个命令中安装多个版本: pyenv install 2.4.3 3.6.8
  • To set a python version as the global version: pyenv global 3.5.2
    要将 python 版本设置为全局版本: pyenv global 3.5.2
    • This is the version of python that will be used by default if a local version (see below) isn't set.
      如果未设置本地版本(见下文),则默认使用此版本的 python。
    • Note: The version must first be installed.
      注意:必须先安装该版本。
  • To set a python version as the local version: pyenv local 3.5.2.
    将 python 版本设置为本地版本: pyenv local 3.5.2
    • The version given will be used whenever python is called from within this folder. This is different than a virtual env, which needs to be explicitly activated.
      每当从此文件夹中调用 python 时,都会使用给定的版本。这与虚拟环境不同,虚拟环境需要显式激活。
    • Note: The version must first be installed.
      注意:必须先安装该版本。
  • After (un)installing any libraries using pip or modifying the files in a version's folder, you must run pyenv rehash to update pyenv with new shims for the python and libraries' executables.
    使用 pip 安装(卸载)任何库或修改版本文件夹中的文件后,必须运行 pyenv rehash 以使用 Python 和库可执行文件的新填充程序更新 pyenv。
    • Note: This must be run outside of the .pyenv folder.
      注意:这必须在 .pyenv 文件夹外部运行。
  • To uninstall a python version: pyenv uninstall 3.5.2
    要卸载 python 版本: pyenv uninstall 3.5.2
  • To view which python you are using and its path: pyenv version
    查看您正在使用的Python及其路径: pyenv version
  • To view all the python versions installed on this system: pyenv versions
    查看该系统上安装的所有 python 版本: pyenv versions
  • Update the list of discoverable Python versions using: pyenv update command for pyenv-win 2.64.x and 2.32.x versions
    使用以下命令更新可发现的 Python 版本列表: pyenv-win 2.64.x2.32.x 版本的 pyenv update 命令

How to update pyenv 如何更新 pyenv

  • If installed via pip
    如果通过 pip 安装
    • Add your pyenv-win installation path to easy_install.pth file located in site-packages. This should make pip recognise pyenv-win as installed.
      将 pyenv-win 安装路径添加到站点包中的 easy_install.pth 文件中。这应该使 pip 识别已安装的 pyenv-win。
    • Get updates via pip pip install --upgrade pyenv-win
      通过 pip pip install --upgrade pyenv-win 获取更新
  • If installed via Git
    如果通过 Git 安装
    • Go to %USERPROFILE%\.pyenv\pyenv-win (which is your installed path) and run git pull
      转到 %USERPROFILE%\.pyenv\pyenv-win (这是您的安装路径)并运行 git pull
  • If installed via zip
    如果通过 zip 安装
    • Download the latest zip and extract it
      下载最新的zip并解压
    • Go to %USERPROFILE%\.pyenv\pyenv-win and replace the folders libexec and bin with the new ones you just downloaded
      转到 %USERPROFILE%\.pyenv\pyenv-win 并将文件夹 libexecbin 替换为您刚刚下载的新文件夹
  • If installed via the installer
    如果通过安装程序安装
    • Run the following in a Powershell terminal: &"${env:PYENV_HOME}\install-pyenv-win.ps1"
      在 Powershell 终端中运行以下命令: &"${env:PYENV_HOME}\install-pyenv-win.ps1"

Announcements 公告

To keep in sync with pyenv linux/mac, pyenv-win now installs 64bit versions by default. To support compatibility with older versions of pyenv-win, we maintain a 32bit train (branch) as a separate release.
为了与 pyenv linux/mac 保持同步,pyenv-win 现在默认安装 64 位版本。为了支持与旧版本 pyenv-win 的兼容性,我们维护一个 32 位序列(分支)作为单独的版本。

Both releases can install 64bit and 32bit python versions; the difference is in version names, for example:
两个版本都可以安装64位和32位python版本;区别在于版本名称,例如:

  • 64bit-train (master), i.e. pyenv version 2.64.x
    64bit-train (master),即 pyenv 版本 2.64.x
> pyenv install -l | findstr 3.8
....
3.8.0-win32
3.8.0
3.8.1rc1-win32
3.8.1rc1
3.8.1-win32
3.8.1
3.8.2-win32
3.8.2
3.9.0-win32
3.9.0
....
  • 32bit-train, i.e. pyenv version 2.32.x
    32bit-train,即pyenv版本2.32.x
> pyenv install -l | findstr 3.8
....
3.8.0
3.8.0-amd64
3.8.1rc1
3.8.1rc1-amd64
3.8.1
3.8.1-amd64
3.8.2
3.8.2-amd64
....

Support for Python versions below 2.4 have been dropped since their installers don't install "cleanly" like versions from 2.4 onward and they're predominantly out of use/support in most environments now.
对低于 2.4 的 Python 版本的支持已被删除,因为它们的安装程序不像 2.4 及以后的版本那样“干净”地安装,并且现在在大多数环境中基本上不再使用/支持。

FAQ

Please see the FAQ page.

Changelog

Please see the Changelog page.

How to contribute

  • Fork the project & clone locally.
  • Create an upstream remote and sync your local copy before you branch.
  • Branch for each separate piece of work. It's good practice to write test cases.
  • Do the work, write good commit messages, and read the CONTRIBUTING file if there is one.
  • Test the changes by running tests\bat_files\test_install.bat and tests\bat_files\test_uninstall.bat
  • Push to your origin repository.
  • Create a new Pull Request in GitHub.

Bug Tracker and Support

  • Please report any suggestions, bug reports, or annoyances with pyenv-win through the GitHub bug tracker.

License and Copyright

  • pyenv-win is licensed under MIT 2019

    License: MIT

Author and Thanks

pyenv-win was developed by Kiran Kumar Kotari and Contributors Thanks for all Contributors and Supports for patience for the latest major release.