How can I activate a virtual env with pyenv?
Asked Answered
C

4

31

I followed this guide to install pyenv in order to manage all Python versions I have installed on my Mac. 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. If I type:

pyenv version

Output:

3.7.3

But apparently this is not enough to activate the venv.

Caresse answered 10/7, 2020 at 19:43 Comment(3)
Maybe you might take a look at native venv. Can be create using "python3 -m venv ." Dot can be replaced with your desired path to install virtual environmentWoodsy
Your tutorial says nothing about the activation of the virtual environmentSmiga
It's explained here.Oversubtlety
H
41

List Python versions in the terminal:

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

Install Python version if not in list:

pyenv install 3.8.6

Create a virtual env with a Python version:

pyenv virtualenv 3.8.6 project1

List versions of virtual environments:

pyenv versions

Activate a virtual version:

pyenv activate project1
Hillside answered 22/2, 2021 at 14:35 Comment(4)
How to verify python version that used by the pyenv ?Propositus
@MohammadReza pyenv which pythonGeri
bit confused virtualenv and activate are not recognised ....Encomium
@Encomium You have to install the pyenv-virtualenv plugin. With Homebrew, you can use brew install pyenv-virtualenv.Pearlinepearlman
S
12
  1. pyenv global 3.7.3
    

    sets the global version of Python to 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.

  2. In order to activate the virtual environment use

    pyenv activate <name>
    

    and to deactivate the virtual environment use

    pyenv deactivate
    
  3. For more details check, this link https://github.com/pyenv/pyenv-virtualenv

Smiga answered 11/7, 2020 at 0:46 Comment(0)
B
2

If you're using virtualenv, just type

pyenv virtualenvs

Then to activate a particular env

pyenv activate [name]

Barns answered 23/5, 2022 at 22:45 Comment(0)
M
1

If pyenv lists an error when using any commands for example:

pyenv: no such command 'activate'

check if you have pyenv-virtualenv package installed. Universal command to install:

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

Marva answered 6/11, 2022 at 15:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.