How to use Pyenv

What is Pyenv?

--Easily switch between multiple versions of Python. --Various versions of Python are placed under ~ / .pyenv.

Location of Pyenv

pyenv/pyenv

This work environment

Installation

Try installing with pyenv-installer.

$ curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash

Write settings to .bashrc

$ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(pyenv init -)"' >> ~/.bashrc
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
$ source ~/.bashrc
$ pyenv -v
pyenv 1.0.10-2-geef042a

Pyenv commands

--The command is described in detail here. --If the installation fails, there are various notes in here. --A list of python versions that can be installed with pyenv install --list. --If you do something like pyenv install 3.6.1, 3.6.1 will be installed. --pyenv versions will show you the installed list and tell you which version is currently active.

$ pyenv install --list
$ 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
$ pyenv install 3.6.1
$ pyenv install anaconda3-4.3.1
$ pyenv versions
* system (set by /root/.pyenv/version)
  3.6.1
  anaconda3-4.3.1

Try switching versions

Check the current version

$ python --version
Python 2.7.12

Use the global command to switch versions.

$ pyenv global 3.6.1
$ pyenv versions
  system
* 3.6.1 (set by /root/.pyenv/version)
  anaconda3-4.3.1
$ python --version
Python 3.6.1

Use the local command to switch versions.

--Can be used when you want to switch versions only in a specific directory. --When pyenv local is executed, a file called .python-version is created in the current directory where it was executed. This takes precedence over the global setting.

$ cd hoge
$ pyenv local anaconda3-4.3.1
$ python --version
Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
$ cd ..
$ python --version
Python 3.6.1

By the way, when I looked at the contents of .python-version, only the version name was written.

$ cat .python-version
anaconda3-4.3.1

Check Python location (full path)

$ pyenv which python3.6
/root/.pyenv/versions/3.6.1/bin/python3.6

By the way, I also try the ordinary which.

$ which python3.6
/root/.pyenv/shims/python3.6
$ which python
/root/.pyenv/shims/python

Recommended Posts

How to use Pyenv
How to use xml.etree.ElementTree
How to use Python-shell
How to use tf.data
How to use virtualenv
How to use Seaboan
How to use image-match
How to use shogun
How to use Pandas 2
How to use Virtualenv
How to use numpy.vectorize
How to use partial
How to use Bio.Phylo
How to use SymPy
How to use WikiExtractor.py
How to use IPython
How to use virtualenv
How to use Matplotlib
How to use iptables
How to use numpy
How to use TokyoTechFes2015
How to use venv
How to use dictionary {}
How to use list []
How to use python-kabusapi
How to use OptParse
How to use return
How to use dotenv
How to use pyenv-virtualenv
How to use Go.mod
How to use imutils
How to use import
How to use Qt Designer
[gensim] How to use Doc2Vec
python3: How to use bottle (2)
Understand how to use django-filter
How to use the generator
[Python] How to use list 1
How to use FastAPI ③ OpenAPI
How to unlock pyenv global
How to use Python argparse
How to uninstall pyenv itself
How to use IPython Notebook
[Note] How to use virtualenv
How to use redis-py Dictionaries
Python: How to use pydub
[Python] How to use checkio
[Go] How to use "... (3 periods)"
How to use tkinter with python in pyenv
How to use Django's GeoIp2
How to use Ruby's PyCall to enable pyenv Python
[Python] How to use input ()
How to use the decorator
[Introduction] How to use open3d
How to use Python lambda
How to use Jupyter Notebook
[Python] How to use virtualenv
python3: How to use bottle (3)
python3: How to use bottle
How to use Google Colaboratory
How to use Python bytes