tech.chakapoko.com
Home / Python / 開発環境

[Python]Pythonをソースコードからインストールする

ソースコードの取得

Pythonのソースコードは公式サイトから取得できます。

上記リンクから最新版のダウンロードページに進み、Gzipped source tarballまたはXZ compressed source tarballをダウンロードします。今回はPython 3.8.2のGzipped source tarballをダウンロードしました。

ダウンロードしたファイルを展開し、展開したディレクトリを作業ディレクトリとします。

$ tar xf Python-3.8.2.tgz
$ cd Python-3.8.2

さらに ./configure, make, make install を実行してインストールします

$ ./configure
$ make
$ make install

インストールする場所を指定する

--prefix で指定します。例えば $HOME/opt/pkg/python-3.8.2 にインストールするなら次のように指定します。

$ ./configure --prefix=$HOME/opt/pkg/python-3.8.2

ライブラリの場所を指定する

./configure を実行するとシステムに用意されているライブラリを利用してビルドされますが、自分でライブラリの場所を指定することができます。例えば $HOME/opt/pkg/openssl-1.1.0h にインストールしたOpenSSLを利用したいときには次のようにビルドオプションを指定します

$ ./configure --with-openssl=$HOME/opt/pkg/openssl-1.1.0h

ビルドオプションの詳細を確認する

詳細なビルドオプションは ./configure --help で確認できます。

$ ./configure --help
`configure' configures python 3.8 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]
  --runstatedir=DIR       modifiable per-process data [LOCALSTATEDIR/run]
  --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-optimizations  Enable expensive, stable optimizations (PGO, etc).
                          Disabled by default.
  --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", "intel-64",
                          or "all")
  --with-framework-name=FRAMEWORK
                          specify an alternate name of the framework built
                          with --enable-framework
  --with-cxx-main=<compiler>
                          compile main() and link python executable with C++
                          compiler
  --with-suffix=.exe      set executable suffix
  --with-pydebug          build with Py_DEBUG defined
  --with-trace-refs       enable tracing references for debugging purpose
  --with-assertions       build with C assertions enabled
  --with-lto              Enable Link Time Optimization in any build. Disabled
                          by default.
  --with-hash-algorithm=[fnv|siphash24]
                          select hash algorithm
  --with-address-sanitizer
                          enable AddressSanitizer (asan)
  --with-memory-sanitizer enable MemorySanitizer (msan)
  --with-undefined-behavior-sanitizer
                          enable UndefinedBehaviorSanitizer (ubsan)
  --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(out)-doc-strings disable/enable documentation strings
  --with(out)-pymalloc    disable/enable specialized mallocs
  --with(out)-c-locale-coercion
                          disable/enable C locale coercion to a UTF-8 based
                          locale
  --with-valgrind         Enable Valgrind support
  --with(out)-dtrace      disable/enable DTrace support
  --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
  --with-openssl=DIR      root of the OpenSSL directory
  --with-ssl-default-suites=[python|openssl|STRING]
                          Override default cipher suites string, python: use
                          Python's preferred selection (default), openssl:
                          leave OpenSSL's defaults untouched, STRING: use a
                          custom string, PROTOCOL_SSLv2 ignores the setting

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<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor
  PROFILE_TASK
              Python args for PGO generation task
  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 <https://bugs.python.org/>.