Idempotent automation of Python and PyPI setup

For the Python environment, visit pyenv. The assumption is an OS X environment. Install readline with Homebrew in advance.

CWD=$(pwd)

PYENV="${HOME}/.pyenv"
PYVER='3.5.0'

if ! which pyenv &> /dev/null
then
    [ ! -d ${PYENV} ] && git clone git://github.com/yyuu/pyenv.git ${PYENV}
    export PATH="${PYENV}/bin:${PATH}"
    eval "$(pyenv init -)"
else
    cd ${PYENV}
    git pull
    cd ${CWD}
fi

if ! pyenv versions | grep ${PYVER} &> /dev/null
then
    CFLAGS="-I$(brew --prefix readline)/include" \
    LDFLAGS="-L$(brew --prefix readline)/lib" \
    pyenv install ${PYVER}
fi

pyenv global ${PYVER}
pyenv rehash

unset PYENV PYVER

if which pip &> /dev/null
then
    PIPS=(
        'ansible'
        'awscli'
        'fabric'
        'flake8'
    )

    for PIP in "${PIPS[@]}"
    do
        pip install --upgrade ${PIP}
    done

    pyenv rehash

    unset PIPS PIP
fi

unset CWD

After installation, add the following line to $ {HOME} /. Bash_profile:

export PATH="${HOME}/.pyenv/bin:${PATH}"
eval "$(pyenv init -)"
[ -f "${HOME}/.pyenv/completions/pyenv.bash" ] && source "${HOME}/.pyenv/completions/pyenv.bash"

Recommended Posts

Idempotent automation of Python and PyPI setup
Source installation and installation of Python
Environment construction of python and opencv
The story of Python and the story of NaN
Installation of SciPy and matplotlib (Python)
This and that of python properties
Coexistence of Python2 and 3 with CircleCI (1.0)
Summary of Python indexes and slices
Reputation of Python books and reference books
[Automation] Manipulate mouse and keyboard with Python
Extraction of tweet.js (json.loads and eval) (Python)
Connect a lot of Python or and and
[Python] Various combinations of strings and values
Full understanding of Python threading and multiprocessing
Project Euler # 1 "Multiples of 3 and 5" in Python
Introduction of Python
Correspondence summary of array operation of ruby and python
Summary of the differences between PHP and Python
The answer of "1/2" is different between python2 and 3
Specifying the range of ruby and python arrays
Installation of Python3 and Flask [Environment construction summary]
Basics of Python ①
Basics of python ①
Compare the speed of Python append and map
[Python] Chapter 02-01 Basics of Python programs (operations and variables)
Copy of python
setup of pyenv-virtualenv
Implementation of TRIE tree with Python and LOUDS
python development environment -use of pyenv and virtualenv-
Comparison of R and Python writing (Euclidean algorithm)
I / O related summary of python and fortran
[Python] A rough understanding of iterators, iterators, and generators
About the * (asterisk) argument of python (and itertools.starmap)
A discussion of the strengths and weaknesses of Python
About shallow and deep copies of Python / Ruby
Continuation of multi-platform development with Electron and Python
Explanation of edit distance and implementation in Python
[Python] Class type and usage of datetime module
Example of reading and writing CSV with Python
Comparison of Python and Ruby (Environment / Grammar / Literal)
Introduction of Python
Basic operation of Python Pandas Series and Dataframe (1)
"Linear regression" and "Probabilistic version of linear regression" in Python "Bayesian linear regression"
Prepared for date calculation and automation of my bot
Mayungo's Python Learning Note: List of stories and links
Full-width and half-width processing of CSV data in Python
The story of Python without increment and decrement operators.
Calculation of standard deviation and correlation coefficient in Python
[Python of Hikari-] Chapter 06-02 Function (argument and return value 1)
List of Python libraries for data scientists and data engineers
The process of installing Atom and getting Python running
Python netCDF4 read speed and nesting of for statements
Python --Explanation and usage summary of the top 24 packages
[Python] Type Error: Summary of error causes and remedies for'None Type'
Receives and outputs standard output of Python 2 and Python 3> C implementations
Easy partial download of mp4 with python and youtube-dl!
Difference between Ruby and Python in terms of variables
Indent behavior of json.dumps is different between python2 and python3
Visualize the range of interpolation and extrapolation with python
Referencing and changing the upper bound of Python recursion
[python] Calculation of months and years of difference in datetime