Skip to content

Instantly share code, notes, and snippets.

@momota
Last active May 28, 2018 05:16
Show Gist options
  • Save momota/f325218c1ca765cc4c97a72158021296 to your computer and use it in GitHub Desktop.
Save momota/f325218c1ca765cc4c97a72158021296 to your computer and use it in GitHub Desktop.
Build a python environment for Mac OSX

1: Install pyenv

  • Install pyenv via github and set your *shrc
$ git clone https://github.com/yyuu/pyenv.git ~/.pyenv
$ echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
$ echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
$ echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.zshrc
$ source ~/.zshrc
# OR $ exec "$SHELL"
  • Then, you can use pyenv command.
$ pyenv -v
  pyenv 1.1.3-7-g0c909f7

2: Install anaconda

  • Confirm latest anaconda version.
$ pyenv install -l | grep ana
  anaconda-1.4.0
(-- snip --)
  anaconda3-4.3.0
  anaconda3-4.3.1
  anaconda3-4.4.0
  • Install latest anaconda by using pyenv.
$ pyenv install anaconda3-4.4.0
Downloading Anaconda3-4.4.0-MacOSX-x86_64.sh...
-> https://repo.continuum.io/archive/Anaconda3-4.4.0-MacOSX-x86_64.sh
Installing Anaconda3-4.4.0-MacOSX-x86_64...
Installed Anaconda3-4.4.0-MacOSX-x86_64 to /Users/momota/.pyenv/versions/anaconda3-4.4.0

$ pyenv rehash
$ pyenv global anaconda3-4.4.0
  • Confirm python environment.
$ pyenv versions
  system
* anaconda3-4.4.0 (set by /Users/momota/.pyenv/version)

3: Create local environment

  • Make a working directory as you like.
$ mkdir -p ~/directory-which-you-like
$ cd $_
  • Create virtual environment by using anaconda
$ pyenv local anaconda3-4.4.0
$ pyenv rehash

$ conda create -n py3.6 python=3.6 anaconda
-- (snip) --
# To activate this environment, use:
# > source activate py3.6
#
# To deactivate this environment, use:
# > source deactivate py3.6
  • Set up local environment using the previous virtual environment.
$ pyenv local anaconda3-4.4.0/envs/py3.6
$ cat .python-version
anaconda3-4.4.0/envs/py3.6
  • Activate your virtual environment.
$ source $PYENV_ROOT/versions/anaconda3-4.4.0/bin/activate py3.6

# If you want to deactive this environment, execute as below
$ source $PYENV_ROOT/versions/anaconda3-4.4.0/bin/deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment