[PYTHON] setup of pyenv-virtualenv

Prologue

Set up a Python virtual environment. It seems that we are working on several projects, so we need various environments in parallel. You can use pyenv-virtualenv to create an isolated virtual environment.

Installation

CentOS8

Advance preparation

dnf -y install git
dnf -y groupinstall "Development Tools"
dnf -y install readline-devel zlib-devel bzip2-devel sqlite-devel openssl-devel

pyenv

git clone https://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
source ~/.bash_profile
exec $SHELL -l

pyenv-virtualenv

git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
exec $SHELL -l

Mac

Advance preparation

$ brew update
$ brew install zlib

Mojave compatible 2019/02/15

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

pyenv, pyenv-virtualenv

$ brew install pyenv
$ brew install pyenv-virtualenv

Environmental setting

$ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

Operation

List of installable versions

$ pyenv install --list

Python installation

$ pyenv install 3.7.2

Creating a virtual environment

An isolated virtual environment is created based on the specified version.

pyenv virtualenv 3.7.2 (Project name)

Automatic switching

When you enter the project directory, you will be able to automatically switch to the virtual environment.

echo (Project name) > (Project name)/.python-version

Delete virtual environment

pyenv virtualenv-delete (Project name)

Recommended Posts

setup of pyenv-virtualenv
Summary of how to use pyenv-virtualenv
onnxruntime-gpu setup
Let's claim the possibility of pyenv-virtualenv in 2021
About the arguments of the setup function of PyCaret
OpenERP 7.0 setup
Idempotent automation of Python and PyPI setup