Python multi-environment management tool - pyenv-win installation and usage tutorial

Table of contents

Introduction to pyenv-win

pyenv-win installation

Configure environment variables

Basic commands of pyenv

pyenv installs py environment

Problems encountered during pyenv installation

pycharm test


Introduction to pyenv-win

What is pyenv-win : It is a tool for managing Python versions on Windows systems. It is the windows version of pyenv and aims to provide functionality similar to pyenv on unix/linux systems. Allows users to install multiple python versions on the same computer and easily switch environments between them. Using pyenv-win, you can easily install, manage and switch various python versions without manually changing system environment variables.

pyenv-win application scenarios : pyenv-win can be applied in various fields, but it is especially useful in machine learning. In the field of machine learning, multiple Python libraries and tools are usually required for tasks such as data processing, model training, and prediction. Different libraries and tools may have different requirements for different versions of python, so using pyenv-win makes it easy to manage these different versions of python and switch to specific environments to meet different needs.

Features of pyenv-win : A lightweight python version management tool, compared to the same python management tool Anaconda, it is smaller in size and also provides virtual environment support, which can create independent python environments for different projects. This avoids dependency conflicts between different projects. This is especially important for machine learning projects, as different projects may require different versions of python and different libraries.

In short, pyenv-win is a very useful tool that can help machine learning developers easily manage multiple python versions and virtual environments, thereby improving development efficiency and project maintainability. For developers who have multiple python environment needs, pyenv-win is a good choice!

pyenv-win installation

Open the pyenv-win download address , click Code, and then click Download ZIP to download the compressed package:

Unzip the pyenv-win compressed package to a directory without Chinese characters, and rename the folder name to pyenv:

Open the folder, find the bin directory, and copy the folder path:

Configure environment variables

Enter "Advanced System Settings" in the computer search box, open it and click Environment Variables:

Click New in the system variables, then add PYENV to the system variables, configure the directory copied above, and click Confirm:

Find the Path variable in the system variables, double-click to open it, add the following two lines of paths, and then click OK. After clicking OK inside, click OK on the environment variables.

%PYENV%\bin 
%PYENV%\shims

At this point, the environment variable configuration is completed. In order to verify whether our configuration is successful, the cmd terminal executes pyenv. The following interface appears, indicating that we have successfully installed:

Basic commands of pyenv

The following are the common commands of pyenv. After mastering these basic commands, you can easily switch the python version in the project:

View the list of python versions supported by pyenv-win:

pyenv install --list

Check the current corresponding version of python:

pyenv version

View all python versions installed on your computer:

pyenv versions

Install specified version || You can also install multiple versions in one command:

pyenv install <version> || pyenv install <version> <version>

Uninstall the specified version:

pyenv uninstall <version>

Set the python version to the global version (the python version used by default) Note: This version must be installed first.

pyenv global <version>

Set the local version (Whenever python is called in this folder, the given version will be used.) Note: This version must be installed first.

pyenv local <version>

Check the python version to check:

python -V

The pyenv-win command given on the official website is as follows, you can understand it yourself:

commands  -------------列出所有可用的pyenv命令
duplicate   -------------创建一个重复的python环境
local        --------------设置或显示特定于本地应用程序的Python版本
global     --------------设置或显示全局Python版本
shell        --------------设置或显示特定于shell的Python版本
install      --------------Python构建安装Python版本
uninstall    -------------卸载特定的Python版本
update      -------------更新缓存的版本数据库
rehash      -------------重新安装pyenv垫片(安装可执行文件后运行此操作)
vname       -------------显示当前的Python版本
version      -------------显示当前Python版本及其来源
version-name ----------------显示当前的Python版本
versions    -----------------列出pyenv可用的所有Python版本
exec        -----------------通过首先准备路径来运行可执行文件,以便选定的Python
which       -------------- 显示可执行文件的完整路径
whence     ---------------------列出包含给定可执行文件的所有Python版本

pyenv installs py environment

Using pyenv to install the py environment does not require us to manually set the python environment variables. pyenv will automatically set them for us. Next, we start to install the python environment, as follows:

1) Check the python environment that pyenv supports installation

2) Install the python version you want to download (you can download multiple)

3) View all python versions installed on your computer:

4) Set version 3.8.0 as the global version and view the currently set global version:

5) Check the current python version:

Problems encountered during pyenv installation

The following problems may occur when installing the python version. You can set it according to your own situation:

1) The installed python version is stuck on the interface (or the request times out).

This situation is generally due to network problems, because the python installed is on a foreign site. There are three ways to solve it:

The first method: use cmd as a proxy and need to access the Internet scientifically. Friends who do not have this condition can directly pass and see the following method.

The second way: Manual installation, open the historical version address  and find the version number you want to download. Take 3.8.0-amd64.exe as an example. After downloading, drag it directly into the install_cache folder of pyenv, and then execute the above installation command. , you can install the corresponding version

The third method (recommended by bloggers): Find the .versions_cache.xml file in the pyenv-win folder and perform the following operations. Changing the mirror source can make our download more convenient:

Replace all https://www.python.org/ftp/python with https://npm.taobao.org/mirrors/python

2) After installing the python version on win11 system, nothing happens when executing python -V (except maybe win10)

This situation is generally caused by the Win11 system management application execution alias. We need to click the win key to enter "Management Application Execution Alias", and then turn off the following two:

pycharm test

Pycharm is an editor tool for writing py. There are a lot of installation tutorials on the Internet, all of which are fool-proof tutorials. I won’t go into details here. Next, let’s use the python environment we just installed to see if we can run through it in pycharm!

First of all, we need to know where the path of the python environment we installed through pyenv is. Execute the following command on the terminal:

pyenv which python

This command will output the path of the currently activated Python environment. as follows:

Where 3.8.0 is the currently activated Python version number. If you want to get the path of other installed Python versions, you can replace python in the command with the corresponding version number. The command will output the path of the Python environment with version number 3.8.7. as follows

pyenv which 3.8.7

After finding the python path we installed, we start configuring the python interpreter for pycharm:

Add the system interpreter according to the previous path, configure the python environment, then click Apply and confirm:

Next we start writing hello world and see if the code can run?

At this point, the installation of the python environment has been completed. Let’s try it now!

Guess you like

Origin blog.csdn.net/qq_53123067/article/details/135329343