AWS / PHP / Python ちょいメモ

amazon web service , PHP, Python を使ったときのメモ。日本語でググってもわからなかった事を中心に。

Mac に pythonz 入れる時の OPTION 設定

以前書いた pythonz on Mac の手順が、通用しないようだったので修正方法を探ってみました。

結果としては、pythonz で install する時にオプション設定をすることで解決しました。

MacOS ver 10.11.6 (OS X El Capitan)
/usr/local/opt/openssl 1.0.2j (by homebrew)
pythonz 2.0.1
導入する python 3.5.2

変わってたところ : OpenSSL on brew

以前は --force 使って手順進めてましたが、現在のバージョンでは、こんなメッセージがでて link できません。
代わりにコンパイラにパスを渡せと。

$ brew link openssl --force
Warning: Refusing to link: openssl
Linking keg-only openssl means you may end up linking against the insecure,
deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

pythonz にパスを渡すには

pythonz install の オプションに "-C CONFIGURE_OPTIONS, --configure=CONFIGURE_OPTIONS" がありましたので、こちらを利用します。後述するように 導入するPythonの configure オプションを確認して、次のように引数を設定しました。

$ pythonz install --configure='LDFLAGS="-L/usr/local/opt/openssl/lib" CFLAGS="-I/usr/local/opt/openssl/include"' 3.5.2

pythonz の install オプションのヘルプ

$ pythonz install -h
Usage: pythonz install [OPTIONS] VERSION

Options:
-h, --help show this help message and exit
-t TYPE, --type=TYPE Type of Python version: cpython, stackless, pypy,
pypy3 or jython.
-f, --force Force installation of python even if tests fail.
--run-tests Run `make test` after compiling.
--url=URL URL used to download the specified python version.
--file=FILE File pinting to the python version to be installed.
-v, --verbose Display log information on the console.
-C CONFIGURE_OPTIONS, --configure=CONFIGURE_OPTIONS
Options passed directly to configure.
--framework Build Framework. (OSX only)
--universal Build for both 32 & 64 bit Intel. (OSX only)
--shared Build shared libraries.
--reinstall Reinstall Python version, if already installed.
--external=EXTERNAL_PATH
Install Python version in specified directory.

Python 3.5.2 configure の ヘルプ

$ ./configure --help
`configure' configures python 3.5 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
-h, --help display this help and exit
--help=short display options specific to this package
--help=recursive display the short help of all the included packages
-V, --version display version information and exit
-q, --quiet, --silent do not print `checking ...' messages
--cache-file=FILE cache test results in FILE [disabled]
-C, --config-cache alias for `--cache-file=config.cache'
-n, --no-create do not create output files
--srcdir=DIR find the sources in DIR [configure dir or `..']

Installation directories:
--prefix=PREFIX install architecture-independent files in PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]

By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.

For better control, use the options below.

Fine tuning of the installation directories:
--bindir=DIR user executables [EPREFIX/bin]
--sbindir=DIR system admin executables [EPREFIX/sbin]
--libexecdir=DIR program executables [EPREFIX/libexec]
--sysconfdir=DIR read-only single-machine data [PREFIX/etc]
--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
--localstatedir=DIR modifiable single-machine data [PREFIX/var]
--libdir=DIR object code libraries [EPREFIX/lib]
--includedir=DIR C header files [PREFIX/include]
--oldincludedir=DIR C header files for non-gcc [/usr/include]
--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]
--datadir=DIR read-only architecture-independent data [DATAROOTDIR]
--infodir=DIR info documentation [DATAROOTDIR/info]
--localedir=DIR locale-dependent data [DATAROOTDIR/locale]
--mandir=DIR man documentation [DATAROOTDIR/man]
--docdir=DIR documentation root [DATAROOTDIR/doc/python]
--htmldir=DIR html documentation [DOCDIR]
--dvidir=DIR dvi documentation [DOCDIR]
--pdfdir=DIR pdf documentation [DOCDIR]
--psdir=DIR ps documentation [DOCDIR]

System types:
--build=BUILD configure for building on BUILD [guessed]
--host=HOST cross-compile to build programs to run on HOST [BUILD]

Optional Features:
--disable-option-checking ignore unrecognized --enable/--with options
--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
--enable-FEATURE[=ARG] include FEATURE [ARG=yes]
--enable-universalsdk[=SDKDIR]
Build fat binary against Mac OS X SDK
--enable-framework[=INSTALLDIR]
Build (MacOSX|Darwin) framework
--enable-shared disable/enable building shared python library
--enable-profiling enable C-level code profiling
--enable-loadable-sqlite-extensions
support loadable extensions in _sqlite module
--enable-ipv6 Enable ipv6 (with ipv4) support
--disable-ipv6 Disable ipv6 support
--enable-big-digits[=BITS]
use big digits for Python longs BITS=30

Optional Packages:
--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
--with-universal-archs=ARCH
select architectures for universal build ("32-bit",
"64-bit", "3-way", "intel", "intel-32", or "all")
--with-framework-name=FRAMEWORK
specify an alternate name of the framework built
with --enable-framework
--without-gcc never use gcc
--with-icc build with icc
--with-cxx-main=
compile main() and link python executable with C++
compiler
--with-suffix=.exe set executable suffix
--with-pydebug build with Py_DEBUG defined
--with-lto Enable Link Time Optimization in PGO builds.
Disabled by default.
--with-hash-algorithm=[fnv|siphash24]
select hash algorithm
--with-address-sanitizer
enable AddressSanitizer
--with-libs='lib1 ...' link against additional libs
--with-system-expat build pyexpat module using an installed expat
library
--with-system-ffi build _ctypes module using an installed ffi library
--with-system-libmpdec build _decimal module using an installed libmpdec
library
--with-tcltk-includes='-I...'
override search for Tcl and Tk include files
--with-tcltk-libs='-L...'
override search for Tcl and Tk libs
--with-dbmliborder=db1:db2:...
order to check db backends for dbm. Valid value is a
colon separated string with the backend names
`ndbm', `gdbm' and `bdb'.
--with-signal-module disable/enable signal module
--with(out)-threads[=DIRECTORY]
disable/enable thread support
--with(out)-thread[=DIRECTORY]
deprecated; use --with(out)-threads
--with(out)-doc-strings disable/enable documentation strings
--with(out)-tsc enable/disable timestamp counter profile
--with(out)-pymalloc disable/enable specialized mallocs
--with-valgrind Enable Valgrind support
--with-fpectl enable SIGFPE catching
--with-libm=STRING math library
--with-libc=STRING C library
--with(out)-computed-gotos
Use computed gotos in evaluation loop (enabled by
default on supported compilers)
--with(out)-ensurepip=[=upgrade]
"install" or "upgrade" using bundled pip

Some influential environment variables:
MACHDEP name for machine-dependent library files
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L if you have libraries in a
nonstandard directory
LIBS libraries to pass to the linker, e.g. -l
CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if
you have headers in a nonstandard directory
CPP C preprocessor
PKG_CONFIG path to pkg-config utility
PKG_CONFIG_PATH
directories to add to pkg-config's search path
PKG_CONFIG_LIBDIR
path overriding pkg-config's built-in search path

Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.

Report bugs to http://bugs.python.org/.

確認方法

導入したpythonがアクティブになってる際に which pip などとして動作する pip を確認します。導入した python と同じフォルダに同梱されてる pip が動いていればOK。

3.4以降は pip は標準のようですし、pythonz で導入したpython は、バージョンによらず pip , setuptools は導入するように作られてるようなので、もしOSオリジナルのpipが動作していれば、オカシイなぁと思って再installという流れでしょうか。

トラブルシュート

pythonz で入れた python の動作が何やら怪しい場合には、こちらをチェック。SSLが必要な設定がスキップされてるときには、次のように記録されていました。

~/.pythonz/log/build.log

if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python.exe -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS

ちなみに導入が成功した場合のログ。pip も setuptools も導入が成功しています。

if test "xupgrade" != "xno" ; then \
case upgrade in \
upgrade) ensurepip="--upgrade" ;; \
install|*) ensurepip="" ;; \
esac; \
./python.exe -E -m ensurepip \
$ensurepip --root=/ ; \
fi
Ignoring indexes: https://pypi.python.org/simple
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-8.1.1 setuptools-20.10.1

参考

configure に どうやってパスを渡すかがわからず苦労しました。