Overview
- About anaconda
- Environment
- How to install
- Install pyenv
- Install anaconda by pyenv
- Activate python of anaconda
- Add library into anaconda
About anaconda
- anaconda for python development
I recommend you to install pyenv if you use homebrew, because config file of anaconda without pyenv is the same as that of homebrew and anaconda without pyenv breaks the config file.
Environment
- Mac OS X 10.14.2 Mojave
- Homebrew 2.0.1
- oh-my-zsh
How to install
Install pyenv
- Update homebrew, and install pyenv
$ brew update
$ brew upgrade
$ brew install pyenv
==> Installing dependencies for pyenv: autoconf, pkg-config and readline
==>/Installing pyenv dependency: autoconf 2
==> Downloading https://homebrew.bintray.com/bottles/autoconf-2.69.mojave.bottle.4.tar.gz
######################################################################## 100.0%
==> Pouring autoconf-2.69.mojave.bottle.4.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/autoconf
==> Summary
ðšn /use/ltcal/Cvllar/autoionf/2.69: 71 files, 3.0MBr e e e
==> Installing pyenv dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pkg-config-0.29.2.mojave.bottle.tar.gz
ðš /usr/local/CellarIpkg-clnfig/0.29.2: 11 f/les, 627.2KB
==> Installing pyenv dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.0.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-8.0.0.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
==> Summary
ðš /usr/local/Cellar/readline/8.0.0: 48 files, 1.5MB
==> Installing pyenv
==> Downloading https://homebrew.bintray.com/bottles/pyenv-1.2.9.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pyenv-1.2.9.mojave.bottle.tar.gz
ðš /usr/local/Cellar/pyenv/1.2.9: 619 files, 2.4MB
==> Caveats
==> autoconf
Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/autoconf
==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
$ pyenv --version ### check pyenv installed
pyenv 1.2.9
Install anaconda by pyenv
- Check version of anaconda you are going to install
$ pyenv install -l | grep anaconda
anaconda-1.4.0
anaconda-1.5.0
anaconda-1.5.1
...
anaconda3-5.2.0
anaconda3-5.3.0
anaconda3-5.3.1
anaconda3-2018.12
- Install anaconda whose version you like.
- I'm installing latest anaconda for python3.x.
$ pyenv install anaconda3-5.3.1
Downloading Anaconda3-5.3.1-MacOSX-x86_64.sh.sh...
-> https://repo.continuum.io/archive/Anaconda3-5.3.1-MacOSX-x86_64.sh
Installing Anaconda3-5.3.1-MacOSX-x86_64.sh...
Installed Anaconda3-5.3.1-MacOSX-x86_64.sh to /Users/user/.pyenv/versions/anaconda3-5.3.1
$ pyenv versions ### check anaconda installed
* system (set by /Users/user/.pyenv/version)
anaconda3-5.3.1
Activate python of anaconda
- Activate anaconda you just installed
$ pyenv global anaconda3-5.3.1 ### select version of anaconda you want to use
$ echo 'eval "$(pyenv init -)"' >> ~/.zprofile ### create PATH for pyenv
$ source ~/.zprofile ### read .zprofile
$ echo 'export PATH="$PYENV_ROOT/versions/anaconda3-5.3.1/bin/:$PATH"' >> ~/.zshrc ### add path for using "conda" command
$ source ~/.zshrc ### read .zshrc
$ conda create --name py python=3.7 anaconda ### add "anaconda" for the last argument so that you can use anaconda libraries in your python environment
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 4.6.2
Please update conda by running
$ conda update -n base -c defaults conda
## Package Plan ##
environment location: /Users/user/.pyenv/versions/anaconda3-5.3.1/envs/py
added / updated specs:
- anaconda
- python=3.7
The following packages will be downloaded:
package | build
---------------------------|-----------------
lz4-c-1.8.1.2 | h1de35cc_0 119 KB
networkx-2.2 | py37_1 2.0 MB
...
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use:
# > source activate py
#
# To deactivate an active environment, use:
# > source deactivate
#
$ source activate py ### the last argument "py" must be the same as name you set by "conda create --name"
(py)
$ ### if you failed like "Usage: pyenv which <command>", read path like "source ~/.zshrc" and "source ~/.zprofile" or restart iTerm2.
$ python3
Python 3.7.0 (default, Jun 28 2018, 07:39:16)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
- Update anaconda
$ conda update conda
$ python3 # check version updated
Python 3.7.2 (default, Dec 29 2018, 00:00:04)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Add library into anaconda
-
Search a library you want to install.
$ anaconda search -t conda [library_name]
-
Get install command.
$ anaconda show [Package the name you searched]
-
Enter install command you just got.
$ conda install --channel [path] [package name]
-
If you make a mistake, uninstall it.
$ conda uninstall [package name]
- For example, install better_exceptions
$ anaconda search -t conda better_exceptions
Using Anaconda API: https://api.anaconda.org
Packages:
Name | Version | Package Types | Platforms | Builds
------------------------- | ------ | --------------- | --------------- | ----------
brianjmcguirk/better_exceptions_fork | 0.2.1.post6 | conda | osx-64 | py37_0
: Pretty and helpful exceptions, automatically
conda-forge/better_exceptions_fork | 0.2.1.post6 | conda | noarch | py_0
: Pretty and helpful exceptions, automatically
jiayi_anaconda/better_exceptions | 0.2.1 | conda | linux-64 | py36_0
: Pretty and helpful exceptions, automatically
Found 3 packages
Run 'anaconda show <USER/PACKAGE>' to get installation details
$ anaconda show conda-forge/better_exceptions_fork
Using Anaconda API: https://api.anaconda.org
Name: better_exceptions_fork
Summary: Pretty and helpful exceptions, automatically
Access: public
Package Types: conda
Versions:
+ 0.2.1.post6
To install this package with conda run:
conda install --channel https://conda.anaconda.org/conda-forge better_exceptions_fork
$ conda install --channel https://conda.anaconda.org/conda-forge better_exceptions_fork
Collecting package metadata: done
Solving environment: done
## Package Plan ##
environment location: /Users/user/.pyenv/versions/anaconda3-5.3.1
added / updated specs:
- better_exceptions_fork
...
$ python3
Python 3.7.2 (default, Dec 29 2018, 00:00:04)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import better_exceptions
>>>
$ # conda uninstall better_exceptions
Trouble
- I can't enter python2 command instead.
$ python2
zsh: command not found: python2
- Path of python may be changed.
$ ls /usr/bin/python
/usr/bin/python*
$ /usr/bin/python
Python 2.7.10 (default, Aug 17 2018, 19:45:58)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Top comments (0)