[PYTHON] pyenv + pyenv-virtualenv (CentOS7)

Overview

I summarized the installation on CentOS. There is little difference from OSX, but it is organized because the prerequisite environment is different.

environment

I am trying in the following environment.

$ uname -r
3.10.0-229.14.1.el7.x86_64
$ lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.1.1503 (Core) 
Release:	7.1.1503
Codename:	Core

Package installation

Installation of packages required for CentOS

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

Install pyenv

https://github.com/yyuu/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

Install pyenv-virtualenv

https://github.com/yyuu/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

Basically, you can use it up to this point.

How to use pyenv

List of installable distributions and versions

pyenv install -l

Installation

Install the version you want to use

pyenv install 2.7.10
pyenv install 3.5.0

List of installed versions

$ pyenv versions
* system (set by /home/saitou/.pyenv/version)
  2.7.10
  3.5.0

Change the version used by default

Don't make any changes to Python on the system side. In the following, the additionally installed 2.7.10 is changed to the default of the user environment.

pyenv global 2.7.10
pip install -U pip

If you want to use Python on the system side, specify system.

$ python -V
Python 2.7.5
$ pyenv global 2.7.10
$ python -V
Python 2.7.10
$ pyenv global system
$ python -V
Python 2.7.5

How to use pyenv + pyenv-virtualenv

pyenv virtualenv <Replication source> <Arbitrary replication name>

I want to use different versions for each project. By doing the following, you can assign a specific directory to a specific version and use it separately.

$ pyenv virtualenv 3.5.0 new_env
$ mkdir -p work/new_project && work/new_project/
$ pyenv versions
* system (set by /home/saitou/.pyenv/version)
  2.7.10
  3.5.0
  new_env
$ pyenv local new_env
pyenv-virtualenv: activate new_env
$ python -V
Python 3.5.0
$ cd ..
pyenv-virtualenv: deactivate new_env
$ python -V
Python 2.7.5
$ cd new_project/
pyenv-virtualenv: activate new_env
$ python -V
Python 3.5.0

Based on 3.5.0, a new environment is duplicated under the new name new_env. You can try different modules because you don't change the environment of the replication source as well as Python on the system side.

Recommended Posts

pyenv + pyenv-virtualenv (CentOS7)
python (pyenv + pyenv-virtualenv) + CentOS7 installation
Install pyenv and pyenv-virtualenv
Install python (pyenv, pyenv-virtualenv)
[CentOS7] Install anaconda using pyenv
Install Python on CentOS using Pyenv
Install Python on CentOS using pyenv
Environment construction with pyenv and pyenv-virtualenv
pyenv note
pyenv notes
system-wide pyenv
pyenv memo
pyenv summary
CentOS8 + Apache2.4 + pyenv + mod_wsgi + Django project deployment
CentOS 7: Enable pyenv with Apache (httpd) CGI
Install pyenv and rbenv on CentOS system-wide
Python 3.x environment construction by Pyenv (CentOS, Ubuntu)