DEV Community

rayvikram
rayvikram

Posted on

Pyenv at a glance

What is pyenv?

  • Want to have multiple python version ( 2.2.x, 2.3.x, 3.5.x, 3.5.x, etc) without messing with your laptop? Manage virtual env easily? Pyenv is your tool.

Installing and configuring pyenv

Some basic commands

pyenv python version control commands

  • pyenv install 3.6.0 - installs python 3.6.0 in pyenv
  • pyenv install --list or pyenv install --list | grep 3.6 view all python version 3.6.x that you can install
  • pyenv global 3.6.0 - activates/enables 3.6.0 version of python
  • python -V or pyenv version -V to view enabled python
  • pyenv versions - list all the python available in pyenv
  • pyenv global system - will undo the activated python and switch to the python install in your machine/system
  • pyenv local 2.7.18 - will create a .python-version file. We use this command to define folder/project specific python. Basically if you are in this folder, python command will be resolved to python 2.7.18. You can also verify it by pyenv versions
  • We can set python version by 3 ways pyenv shell 3.8, pyenv local 2.7.18 and pyenv global 3.5.9

pyenv virtualenv commands

  • pyenv virtualenv <python_version> <env_name> - eg pyenv virtualenv 3.5.9 my_env - will creates a python env with my_env name
  • activate this newly created env - pyenv activate my_env
  • if you want to automatically activate this env after navigating to a project folder if do pyenv virtualenv 3.5.9 my_env > navigate to project > pyenv local my_env > will create .python-version file with content my_env so that pyenv-virtualenv plugin will know that you have already an env for this folder and activates this. Navigating out of this folder will deactivate the env
  • It also supports multiple env at once. pyenv local env1 env2 - command will try to be resolved in env2 if failed then it will use env2

conclusion

  • You have multiple python versions
  • No need to activate env for projects manually

Top comments (0)