DEV Community

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

Posted on

2 1 2 2 2

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
    

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay