본문 바로가기

프로그래밍 언어/Python

Pyenv-version/virtual environment management

List of viable packages

  • venv for python3/virtualenv for python2 (obsolete): manages virtual environments for a specific Python version
  • pyenv: manages multiple versions of Python
  • pyenv-virtualenv: manages virtual environments for different versions of Python
  • pipenv: not recommended because of the reported issue with slow locking (https://github.com/pypa/pipenv/issues/3827)

venv

sudo apt-get install python3-venv
# /working_directory
python3 -m venv [package_folder_to_make]

pyenv

Download dependencies for compiling

sudo apt-get install -y make 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

curl https://pyenv.run | bash

Add the following

# to ~/.bashrc
export PATH="/home/group/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

Look up the list of packages

pyenv install --list

Install any version of any package there is to offer

pyenv install -v 3.7.2

List installed versions

ls ~/.pyenv/versions/

Remove any version simply by deleting the folder

rm -rf ~/.pyenv/versions/2.7.15

or remove using pyenv

pyenv uninstall 2.7.15

List all available versions

pyenv versions

Set the global

pyenv global <version>

Create Python virtual environment

pyenv virtualenv --help
Usage: pyenv virtualenv [-f|--force] [VIRTUALENV_OPTIONS] [version] <virtualenv-name>

pyenv virtualenv 3.8.3 venv

List Python virtual environments

pyenv virtualenvs

Delete Python virtual environment

pyenv virtualenv-delete <virtualenv-name>

Switch/Activate to a Python virtual environment

pyenv activate <virtualenv-name>

Escape from/Deactivate a Python virtual environment

pyenv deactivate

 

python freeze > requirements.txt

References

https://realpython.com/intro-to-pyenv/

'프로그래밍 언어 > Python' 카테고리의 다른 글

파이썬 프로젝트 구조와 패키징  (0) 2020.08.04