DEV Community

Cover image for Setup and Use Pyenv in Python Applications
Wesley Bertipaglia
Wesley Bertipaglia

Posted on

Setup and Use Pyenv in Python Applications

Pyenv is a popular option in Python applications. Pyenv allows you to manage different versions of Python in your application and also on your system.

Pyenv does not officially support Windows but you can use WSL (Windows Subsystem for Linux).

For more information visit: pyenv repository

Installation:

You can install using Homebrew or make a manual installation:

  • Using Homebrew:

    brew install pyenv
    
  • Manual Installation:

    • Download pyenv: bash curl https://pyenv.run | bash
    • Let's edit your bash profile: bash nano .bashrc
    • Add these lines in the end of the document: bash export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init --path)"

Creating a Virtual Environment:

pyenv virtualenv <python_version> <env_name>
Enter fullscreen mode Exit fullscreen mode




Activating the Virtual Environment:


pyenv activate <env_name>
Enter fullscreen mode Exit fullscreen mode




Deactivating the Virtual Environment:


pyenv deactivate
Enter fullscreen mode Exit fullscreen mode




Managing Python Versions:

Pyenv allows you to manage python versions, here is a simple tutorial that you can use in your application or in your input system:

  • List available versions:

    pyenv install -list
    
  • Install a version:

    pyenv install <version>
    
  • Defining a version:

    pyenv global <version> # set a global version
    pyenv local <version> # set a local version
    

Top comments (0)