[miscellaneous] pyenv usage

기타 유용한 pyenv 명령어에 대해 작성합니다.

Python Environment Manager Installation Guide

sudo apt install python3-dev python3-pip

sudo apt-get install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
libreadline-dev libsqlite3-dev \
wget curl llvm libncurses5-dev libncursesw5-dev \
xz-utils tk-dev libffi-dev liblzma-dev python-openssl git
curl https://pyenv.run | bash
Set in ./bashrc
export PATH="/home/[YOUR USER NAME]/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
  • 위 커맨드는 pyenv를 path에 등록해주고 auto completion을 사용할 수 있게 해줍니다.
Setup

exec "$SHELL"

  • 이제 pyenv 를 입력했을때 다음과 같은 command 안내가 나오면 정상적으로 설치된 것입니다.
rilab@rilab-xxx-xx-xxxx:~$ pyenv
pyenv 2.3.20
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   activate    Activate virtual environment
   commands    List all available pyenv commands
   deactivate   Deactivate virtual environment
   doctor      Verify pyenv installation and development tools to build pythons.
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   latest      Print the latest installed or known version with the given prefix
   local       Set or show the local application-specific Python version(s)
   prefix      Display prefixes for Python versions
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall Python versions
   update      Update pyenv, its plugins including the list of available versions
   --version   Display the version of pyenv
   version     Show the current Python version(s) and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   virtualenv   Create a Python virtualenv using the pyenv-virtualenv plugin
   virtualenv-delete   Uninstall a specific Python virtualenv
   virtualenv-init   Configure the shell environment for pyenv-virtualenv
   virtualenv-prefix   Display real_prefix for a Python virtualenv version
   virtualenvs   List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme

pyenv commands

Install

pyenv install --list

  • 설치할 수 있는 python의 version list를 확인합니다.

pyenv virtualenv version-of-python name-of-env

  • ex) pyenv virtualenv 3.8.8 rilab
  • 3.8.8 버전의 rilab 이름을 가지는 가상 환경을 설치합니다.
Uninstall

pyenv uninstall name-of-env

  • ex) pyenv uninstall rilab
  • rilab 이름의 가상환경을 삭제합니다.
Get an Installed virtualenv list

pyenv versions

  • 설치되어 있는 모든 가상환경을 확인할 수 있습니다.



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • [miscellaneous] docker usage
  • [구현] AprilTag Pose Estimation
  • [miscellaneous] linux bash shell script usage
  • [study] Vector Quantization
  • [paper-review] 6-DOF GraspNet: Variational Grasp Generation for Object Manipulation