Catalogue
Installing Python 3.4.3 on macOS

Installing Python 3.4.3 on macOS

🌐 日本語で読む

Overview

I was given a wonderful book called “機械学習養成読本” (Machine Learning Training Reader), and I immediately started studying with it.

On page 115, Part 2, Chapter 1,
“Installing Python” didn’t go smoothly, so here are my notes.

When you run pyenv install 3.4.3, did you get an error like the following?

1
2
3
4
5
6
7
8
9
Downloading Python-3.4.3.tgz...
-> https://www.python.org/ftp/python/3.4.3/Python-3.4.3.tgz
Installing Python-3.4.3...
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?

Please consult to the Wiki page to fix the problem.
https://github.com/yyuu/pyenv/wiki/Common-build-problems

BUILD FAILED (OS X 10.11.2 using python-build 20150519)

Environment

  • MacOSX El Capitan 10.11.2 (15C50)
  • Homebrew 0.9.5
1
2
3
4
5
6
7
8
$ brew install sqlite3
$ brew install readline
$ brew install openssl
$ brew install pyenv
$ export CFLAGS="-I$(brew --prefix openssl)/include"
$ export LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix sqlite3)/lib"
$ export CPPFLAGS="-I$(brew --prefix sqlite3)/include"
$ pyenv install 3.4.3

Setting the following variables that are passed to the compiler was the key.

  • CFLAGS
  • LDFLAGS
  • CPPFLAGS

10.3 Variables Used by Implicit Rules

One thing to be careful about is the Python that comes installed by default on the Mac.
Remove it from Python’s PATH (/usr/local/bin).

1
2
3
4
$ which python
/usr/local/bin/python

$ mv /usr/local/bin/python /usr/local/bin/python2.7.10

If pip is also already installed, remove it from the PATH in the same way.

1
2
3
4
$ which pip
/usr/local/bin/pip

$ mv /usr/local/bin/pip /usr/local/bin/pip2.7

If you haven’t exported any other Python PATH,
the path should now point to the Python installed by pyenv.

1
2
$ which python
/Users/kenzo/.pyenv/shims/python ← If it shows up like this, you're good to go ♪
kenzo0107

kenzo0107