简体   繁体   English

如何用pyenv激活虚拟环境?

[英]How to activate virtual env with pyenv?

I followed this guide to install pyenv in order to manage all python versions I have installed on my Mac.我按照本指南安装pyenv ,以便管理我在 Mac 上安装的所有 python 版本。 However, it is not clear to me what the pyenv global 3.7.3 command does and how I can activate a venv that uses python 3.7.但是,我不清楚pyenv global 3.7.3命令的作用以及如何激活使用 python 3.7 的 venv。 If I type:如果我输入:

$ pyenv version
3.7.3

But apparently this is not enough to activate the venv?但显然这还不足以激活 venv?

list python versions in terminal:列出终端中的 python 版本:

$ pyenv install --list | grep " 3\.[678]"

Install Python version if not in list:如果不在列表中,请安装 Python 版本:

$ pyenv install 3.8.6

Create virtual env with python version:使用 python 版本创建虚拟环境:

$ pyenv virtualenv 3.8.6 project1

List versions of virtual environments:列出虚拟环境的版本:

$ pyenv versions

Activate a virtual version:激活虚拟版本:

pyenv activate project1

pyenv global 3.7.3

sets the global version of Python to 3.7.3.将 Python 的全局版本设置为 3.7.3。 It means that if you decide to use Python on your machine without using a virtual environment, then the version 3.7.3 is going to be used as a default.这意味着如果你决定在你的机器上使用 Python 而不使用虚拟环境,那么版本 3.7.3 将被用作默认值。

2) In order to activate the virtual environment use 2)为了激活虚拟环境使用

pyenv activate <name>

and to deactivate the virtual environment use并停用虚拟环境使用

pyenv deactivate

For more details check this link https://github.com/pyenv/pyenv-virtualenv有关更多详细信息,请查看此链接https://github.com/pyenv/pyenv-virtualenv

If you're using virtualenv, just type如果您使用的是 virtualenv,只需键入

pyenv virtualenvs

Then to activate a particular env然后激活特定的环境

pyenv activate [name]

If pyenv lists an error when using any commands for example:如果 pyenv 在使用任何命令时列出错误,例如:

pyenv: no such command 'activate'

check if you have pyenv-virtualenv package installed.检查你是否安装了 pyenv-virtualenv package。 Universal command to install:通用命令安装:

git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM