Combination of anyenv and direnv

background

The features of each will be given to another page.

Let me give you an example.

There is a bio software package called Qiime, and it is difficult to install it by yourself. I have to install various bio commands,

If you can say that, you don't want to touch it. Furthermore, I want to add a new one to the server,

It feels like

Not just the example above

With bio tools, there are tons of small commands and scripts thrown in.

Even if I try to introduce it, I will wear down my nerves in various ways. Whether there is a command name conflict, how to manage the list installed this time, how to uninstall it, etc. Furthermore, each of them instructed me to set detailed environment variables, and in a blink of an eye, . * Shrc was messed up.

As a matter of course, I want an easy environment switching tool (including environment variables).

Environment switching

You can switch commands with the typical virtualenv and pyenv-virtualenv, but it is difficult to switch environment variables. On the contrary, direnv does not touch the management part of the command.

Therefore,
  1. Command installation management is pyenv (ʻanyenv`)
  2. For verification of small-scale software, create a multi-tenant environment for it and use pyenv shell to skip environment variables on the shell. So that it will be cut off when the work is finished
  1. Leave large-scale software package switching on a daily basis to direnv.
  2. The tools that you have to set up a web server are the same as before.

Based on the simple concept of ʻanyenv direnv`, we decided to install and build the environment. Below, we will use it as an example assuming that an isolated environment of Qiime-1.8.0 will be created.

CentOS 6.6 (some mac)

anyenv

  1. Installation of ʻanyenv` main unit
  2. Install pyenv, plenv, jenv

For now, I don't need any other * env in practice

First, evacuate

python


$ mv .bashrc .bashrc~
$ mv .local .local.bak

If there is something in the common library path such as .local in the remnants of the past, it should be tidied up

anyenv installation

python


$ export PERL5OPT=   #<=Only we need
$ git clone https://github.com/riywo/anyenv ~/.anyenv
$ export PATH=${HOME}/.anyenv/bin:$PATH
$ eval "$(anyenv init -)"

pyenv installation

python


$ anyenv install pyenv
$ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.anyenv/envs/pyenv/plugins/pyenv-virtualenv
$ eval "$(anyenv init -)"     # exec $SHELL -l 
$ pyenv install 2.7.3         # @mac: $ CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 2.7.3
$ pyenv install 3.3.6
$ pyenv rehash

On mac, when installing python

python


$ CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" pyenv install 2.7.3 

If you don't, it won't work

pyenv-virtualenv Create a quarantine environment to use with You can create multiple environments with the same version of python

python


$ pyenv virtualenv 2.7.3 qiime
$ pyenv rehash

plenv installation

plenv


$ anyenv install plenv
$ plenv install 5.20.1
$ plenv shell 5.20.1
$ plenv install-cpanm

cpanm is installed separately

jenv installation

jenv


$ anyenv install jenv
$ alternatives --config java

There are 3 programs'java'To provide.

Select command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.5.0-gcj/bin/java
 + 2           /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
*  3           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
$ jenv add /usr/lib/jvm/jre-1.5.0-gcj 
$ jenv add /usr/lib/jvm/jre-1.6.0-openjdk.x86_64
$ jenv add /usr/lib/jvm/jre-1.7.0-openjdk.x86_64

Fitted

If you're a'mac','gnu screen', and a'zsh' user wants to use ʻanyenv` regularly

python


% cd /etc               
% sudo mv zshenv zshenv.bak 
#% sudo mv zshenv zprofile 

I have to do

If you're using'gnu screen'on'CentOS' and you're using'zsh' and want to use ʻanyenv` regularly

python


% cd /etc
% sudo mv zshrc zshrc.bak

Maybe I have to do it (unverified).

direnv

go install

Without

python


$ wget -q https://storage.googleapis.com/golang/go1.4.linux-386.tar.gz
$ tar zxf go1.4.linux-amd64.tar.gz 
$ mv go ../bin    #Wherever you like
$ cd ../bin/go
$ export GOROOT=$PWD
$ cd go/bin
$ export PATH=$PWD:$PATH

direnv compile-time error if GOROOT is not set

direnv installation

python


$ git clone https://github.com/zimbatm/direnv
$ cd direnv
$ make install DESTDIR=/PATH/TO/DIR  #Wherever you like
$ eval "$(direnv hook bash)"

try

python


$ cat /PATH/TO/.envrc
export FOOBAR=foobar
$ cd /PATH/TO
direnv: loading .envrc                                                                                                                                                                                                                    
direnv: export + FOOBAR

Dissatisfaction

Change the prompt with zsh as well

.envrc


export PROMPT='Qiime-1.8.0 $'

I want to do something, but it doesn't interpret the variables in the prompt, and it's miserable when I move to /. Is it just my environment? I don't want to put .envrc in/,

Operation

Describe the following in .bashrc

.bashrc


export PATH=${HOME}/.anyenv/bin:$PATH
eval "$(anyenv init -)"
eval "$(direnv hook bash)"

Needless to say, the path to ʻanyenv, direnv` is assumed to pass.

At the time of installation

Explicitly enable and install only in that shell, such as with pyenv shell

The individual commands are

python


$ ./configure --prefix=${HOME}/.anyenv/envs/pyenv/versions/qiime

Aim for isolation by

By the way

By pyenv rehash for pyenv, individual commands (such as the installed ghc, which will be mentioned separately) will also be synchronized to $ {HOME} /. Anyenv / envs / pyenv / shims.

python


$ cat ${PYENV_ROOT}/pyenv/shims/ghc
#!/usr/bin/env bash
set -e
[ -n "$PYENV_DEBUG" ] && set -x

program="${0##*/}"
if [ "$program" = "python" ]; then
  for arg; do
    case "$arg" in
    -c* | -- ) break ;;
    */* )
      if [ -f "$arg" ]; then
        export PYENV_DIR="${arg%/*}"
        break
      fi
      ;;
    esac
  done
fi

export PYENV_ROOT="/PATH/TO/.anyenv/envs/pyenv"
exec "/PATH/TO/.anyenv/envs/pyenv/libexec/pyenv" exec "$program" "$@"
$ which ghc
~/.anyenv/envs/pyenv/shims/ghc
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.8.3
$ pyenv shell 3.3.6
$ ghc --version
pyenv: ghc: command not found

The `ghc' command exists in these Python versions:
  qiime

The same was true for plenv. Whether you use it or not

When using commands

Using the function of direnv

For example, only the directories where you want to use Qiime-1.8.0

python


$ cat /PATH/TO/DIR/.envrc
export PYENV_VERSION=qiime
export JENV_VERSION=1.6.0.33
$ direnv allow

If you do

python


$ pyenv versions
* system (set by PYENV_VERSION environment variable)
  2.7.3
  3.3.6
  qiime
$ jenv versions
* system (set by JENV_VERSION environment variable)
  1.5
  1.5.0
  1.6
  1.6.0.33
  1.7
  1.7.0.71
(Omitted)

But

python


$ cd /PATH/TO/DIR
direnv: loading .envrc
direnv: export ~JENV_VERSION ~PYENV_VERSION
$ pyenv versions
  system
  2.7.3
  3.3.6
* qiime (set by PYENV_VERSION environment variable)
$ jenv versions
  system
  1.5
  1.5.0
  1.6
* 1.6.0.33 (set by JENV_VERSION environment variable)
  1.7
  1.7.0.71
(Omitted)

Switch to

Of course, it remains valid in the offspring directory

External commands are also switched properly. ex) blastall

python


$ which blastall
/home/XXXX/.anyenv/envs/pyenv/shims/blastall
$ blastall | head -2 | tail -1
blastall 2.2.26   arguments:   # /usr/local/Version in bin
$ cd /PATH/TO/DIR
direnv: loading .envrc
direnv: export ~JENV_VERSION ~PYENV_VERSION
$ which blastall
/home/XXXX/.anyenv/envs/pyenv/shims/blastall
$ blastall | head -2 | tail -1
blastall 2.2.22   arguments:   #Desired version
$ cd ../
$ direnv: unloading
$ blastall | head -2 | tail -1
blastall 2.2.26   arguments:

Other people

That's fine for personal use, but there are cases where other people on the server want to use it. So, even if someone else copies the above .bashrc as it is, ʻanyenv does not work (direnv works normally as a single unit). If that "other person" is at a level where he can personally install and use ʻanyenv or direnv, well, he'll do whatever he wants, but if not.

.bashrc


eval "$(anyenv init -)" 

, Instead of embedding it as it is, save the result of ʻeval "$ (anyenv init-)" separately and sourcein the target person's.bashrc`.

That way, it behaves as expected.

Recommended Posts

Combination of anyenv and direnv
Combination of recursion and generator
Version control of Node, Ruby and Python with anyenv
Problems of liars and honesty
Mechanism of pyenv and virtualenv
Explanation and implementation of SocialFoceModel
Differentiation of sort and generalization of sort
Coexistence of pyenv and autojump
Use and integration of "Shodan"
Problems of liars and honesty
Occurrence and resolution of tensorflow.python.framework.errors_impl.FailedPreconditionError
Very convenient combination of CLI image viewer Überzug and Ranger
Comparison of Apex and Lamvery
Source installation and installation of Python
Introduction and tips of mlflow.Tracking
[Translation] scikit-learn 0.18 User Guide 4.1. Pipeline and Feature Union: Combination of estimators
Environment construction of python and opencv
Various of Tweepy. Ma ♡ and ♡ me ♡
Basic knowledge of Linux and basic commands
Order of arguments of RegularGridInterpolator and interp2d
The story of Python and the story of NaN
Explanation and implementation of PRML Chapter 4
Introduction and Implementation of JoCoR-Loss (CVPR2020)
Benefits and examples of using RabbitMq
Explanation and implementation of ESIM algorithm
Danger of mixing! ndarray and matrix
Installation of SciPy and matplotlib (Python)
Significance of machine learning and mini-batch learning
Introduction and implementation of activation function
Install GoLang in goenv of anyenv
Misunderstandings and interpretations of Luigi's dependencies
Explanation and implementation of simple perceptron
Calculation of homebrew class and existing class
This and that of python properties
Design of experiments and combinatorial optimization
Installation and easy usage of pytest
Clash of Clans and image analysis (3)
Features of symbolic and hard links
Coexistence of Python2 and 3 with CircleCI (1.0)
[Excel] Addition of character strings (combination)
Summary of Python indexes and slices
Aggregation and visualization of accumulated numbers
Reputation of Python books and reference books
The golden combination of embulk and BigQuery shines even more with Digdag