23

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.

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 environment
    – brtiberio
    Jul 10, 2020 at 20:32
  • 1
    Your tutorial says nothing about the activation of the virtual environment
    – alv2017
    Jul 11, 2020 at 0:47
  • It's explained here.
    – djvg
    Oct 6, 2022 at 13:06

4 Answers 4

30

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
4
  • How to verify python version that used by the pyenv ? Jul 17, 2021 at 11:05
  • @MohammadReza pyenv which python Aug 22, 2021 at 21:53
  • 3
    bit confused virtualenv and activate are not recognised ....
    – cs0815
    Sep 14, 2022 at 12:22
  • @cs0815 You have to install the pyenv-virtualenv plugin. With Homebrew, you can use brew install pyenv-virtualenv. Jul 3 at 5:52
11
  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

1

If you're using virtualenv, just type

pyenv virtualenvs

Then to activate a particular env

pyenv activate [name]

0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.