[Linux] Install virtual python env

1.1 pyenv 설치

1
2
3
$ sudo apt install curl git-core gcc make zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libssl-dev
$ git clone https://github.com/pyenv/pyenv.git $HOME/.pyenv
$ vim $HOME/.bashrc

1.2 configs setting

1
2
3
4
5
6
7
$ vi /.bash_profile

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

1.3 update

1
$ git clone git://github.com/pyenv/pyenv-update.git ~/.pyenv/plugins/pyenv-update

1.4 python 설치

1
$ pyenv install 3.5.2

2.1 pyenv-virtualenv 설치

1
$ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv

2.2 virtualenv 환경변수 추가

1
2
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
$ source ~/.bash_profile

2.3 가상환경 설정

1
$ pyenv virtualenv 3.6.0 py3tensor

2.4 실행

1
$ pyenv activate py3tensor

2.4 해제

1
$ pyenv deactivate

3.1 auto_env 설치

1
2
$ git clone git://github.com/kennethreitz/autoenv.git ~/.autoenv
$ echo 'source ~/.autoenv/activate.sh' >> ~/.bash_profile

3.2 local 지정

1
2
3
$ mkdir pyenv_test && cd pyenv_test
$ touch .env
$ echo "pyenv activate [virtualenv name]" > .env

3.3 global 해제

1
2
$ vi ~/.env
$ echo "pyenv deactivate" > .env

4.1 Jupyter notebook for virtual env

1
2
3
4
5
6
7
8
9
10
11
$ cd pyenv_test
$ pip install ipykernel ipython
$ mkdir /home/henry/.local/share/jupyter/kernels/py3ten
$ vi kernel.jason

{
"argv": [ "/Users/motta/.pyenv/versions/k_means/bin/python", "-m", "ipykernel",
"-f", "{connection_file}"],
"display_name": "k_means",
"language": "python"
}

reference:

https://www.alfredo.motta.name/create-isolated-jupyter-ipython-kernels-with-pyenv-and-virtualenv/

< !-- add by yurixu 替换Google的jquery并且添加判断逻辑 -->