バイオ系博士の備忘録

プログラミング関係の備忘録

pyenvからminiconda環境を構築

普段はpipを使うのですが、condaを使う機会があったので備忘録として残します。
バイオインフォマティクス系の分析はcondaにしかパッケージがないことがあるので、pipできないとconda競合に気をつけないといけません。
pyenvからconda環境を入れることで、なにか困っても再構築が楽になります。
ついでにcookiecutterも使って分析しやすいディレクトリを構成します。

# $ pip install cookiecutter
$ pyenv install miniconda3-latest
$ pyenv shell miniconda3-latest
$ condo create -n [env_name] python=[python_version]
$ condo activate [env_name]
$ conda install jupyter
$ ipython kernel install --user --name=[env_name] --display-name=[env_name]
# if you don’t need this env, type command ‘$ jupyter kernelspec uninstall [env_name]’ 
$ cookiecutter https:github.com/drivendata/cookiecutter-data-science
You've downloaded /Users/YOUR_NAME/.cookiecutters/cookiecutter-data-science before. Is it okay to delete and re-download it? [yes]: yes
project_name [project_name]: [env_name]
repo_name [ml_project]: 
author_name [Your name (or your organization/company/team)]: [your_name]
description [A short description of the project.]:
Select open_source_license:
1 - MIT
2 - BSD-3-Clause
3 - No license file
Choose from 1, 2, 3 (1, 2, 3) [1]: 1
s3_bucket [[OPTIONAL] your-bucket-for-syncing-data (do not include 's3://')]: 
aws_profile [default]: 
Select python_interpreter:
1 - python3
2 - python
Choose from 1, 2 (1, 2) [1]: 1
$ cd [env_name]
# if you need requirements file for pip, type command ‘$ conda list --export > requirements.txt’
# if you want to create env from file, type command ‘$ conda env create -f=[env_name.yml]’
$ conda env export -n [env_name] > [env_name.yml]
# edit gitignore file ‘$ vim .gitignore’
git init

ただし、この方法だとcondaに存在しないパッケージはsystemを検索して利用する罠があります。
とくに、conda install jupyterせずにjupyterカーネルを追加すると、import *** はsystemを検索してしまいます。
途中でjupyterをinstallしているのはそのため。