選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

222 行
8.8 KiB

7年前
7年前
  1. # python-build
  2. python-build is a [pyenv](https://github.com/pyenv/pyenv) plugin that
  3. provides a `pyenv install` command to compile and install different versions
  4. of Python on UNIX-like systems.
  5. You can also use python-build without pyenv in environments where you need
  6. precise control over Python version installation.
  7. See the [list of releases](https://github.com/pyenv/pyenv/releases)
  8. for changes in each version.
  9. ## Installation
  10. ### Installing as a pyenv plugin (recommended)
  11. You need nothing to do since python-build is bundled with pyenv by
  12. default.
  13. ### Installing as a standalone program (advanced)
  14. Installing python-build as a standalone program will give you access to the
  15. `python-build` command for precise control over Python version installation. If you
  16. have pyenv installed, you will also be able to use the `pyenv install` command.
  17. git clone git://github.com/pyenv/pyenv.git
  18. cd pyenv/plugins/python-build
  19. ./install.sh
  20. This will install python-build into `/usr/local`. If you do not have write
  21. permission to `/usr/local`, you will need to run `sudo ./install.sh` instead.
  22. You can install to a different prefix by setting the `PREFIX` environment
  23. variable.
  24. To update python-build after it has been installed, run `git pull` in your cloned
  25. copy of the repository, then re-run the install script.
  26. ### Installing with Homebrew (for OS X users)
  27. Mac OS X users can install python-build with the [Homebrew](http://brew.sh)
  28. package manager. This will give you access to the `python-build` command. If you
  29. have pyenv installed, you will also be able to use the `pyenv install` command.
  30. *This is the recommended method of installation if you installed pyenv with
  31. Homebrew.*
  32. brew install pyenv
  33. Or, if you would like to install the latest development release:
  34. brew install --HEAD pyenv
  35. ## Usage
  36. Before you begin, you should ensure that your build environment has the proper
  37. system dependencies for compiling the wanted Python Version (see our [recommendations](https://github.com/pyenv/pyenv/wiki#suggested-build-environment)).
  38. ### Using `pyenv install` with pyenv
  39. To install a Python version for use with pyenv, run `pyenv install` with
  40. exact name of the version you want to install. For example,
  41. pyenv install 2.7.4
  42. Python versions will be installed into a directory of the same name under
  43. `~/.pyenv/versions`.
  44. To see a list of all available Python versions, run `pyenv install --list`. You
  45. may also tab-complete available Python versions if your pyenv installation is
  46. properly configured.
  47. ### Using `python-build` standalone
  48. If you have installed python-build as a standalone program, you can use the
  49. `python-build` command to compile and install Python versions into specific
  50. locations.
  51. Run the `python-build` command with the exact name of the version you want to
  52. install and the full path where you want to install it. For example,
  53. python-build 2.7.4 ~/local/python-2.7.4
  54. To see a list of all available Python versions, run `python-build --definitions`.
  55. Pass the `-v` or `--verbose` flag to `python-build` as the first argument to see
  56. what's happening under the hood.
  57. ### Custom definitions
  58. Both `pyenv install` and `python-build` accept a path to a custom definition file
  59. in place of a version name. Custom definitions let you develop and install
  60. versions of Python that are not yet supported by python-build.
  61. See the [python-build built-in definitions](https://github.com/pyenv/pyenv/tree/master/plugins/python-build/share/python-build) as a starting point for
  62. custom definition files.
  63. [definitions]: https://github.com/pyenv/pyenv/tree/master/plugins/python-build/share/python-build
  64. ### Special environment variables
  65. You can set certain environment variables to control the build process.
  66. * `TMPDIR` sets the location where python-build stores temporary files.
  67. * `PYTHON_BUILD_BUILD_PATH` sets the location in which sources are downloaded and
  68. built. By default, this is a subdirectory of `TMPDIR`.
  69. * `PYTHON_BUILD_CACHE_PATH`, if set, specifies a directory to use for caching
  70. downloaded package files.
  71. * `PYTHON_BUILD_MIRROR_URL` overrides the default mirror URL root to one of your
  72. choosing.
  73. * `PYTHON_BUILD_SKIP_MIRROR`, if set, forces python-build to download packages from
  74. their original source URLs instead of using a mirror.
  75. * `PYTHON_BUILD_ROOT` overrides the default location from where build definitions
  76. in `share/python-build/` are looked up.
  77. * `PYTHON_BUILD_DEFINITIONS` can be a list of colon-separated paths that get
  78. additionally searched when looking up build definitions.
  79. * `CC` sets the path to the C compiler.
  80. * `PYTHON_CFLAGS` lets you pass additional options to the default `CFLAGS`. Use
  81. this to override, for instance, the `-O3` option.
  82. * `CONFIGURE_OPTS` lets you pass additional options to `./configure`.
  83. * `MAKE` lets you override the command to use for `make`. Useful for specifying
  84. GNU make (`gmake`) on some systems.
  85. * `MAKE_OPTS` (or `MAKEOPTS`) lets you pass additional options to `make`.
  86. * `MAKE_INSTALL_OPTS` lets you pass additional options to `make install`.
  87. * `PYTHON_CONFIGURE_OPTS` and `PYTHON_MAKE_OPTS` and `PYTHON_MAKE_INSTALL_OPTS` allow
  88. you to specify configure and make options for building CPython. These variables
  89. will be passed to Python only, not any dependent packages (e.g. libyaml).
  90. ### Applying patches to Python before compiling
  91. Both `pyenv install` and `python-build` support the `--patch` (`-p`) flag that
  92. signals that a patch from stdin should be applied to Python, Jython or PyPy
  93. source code before the `./configure` and compilation steps.
  94. Example usage:
  95. ```sh
  96. # applying a single patch
  97. $ pyenv install --patch 2.7.10 < /path/to/python.patch
  98. # applying a patch from HTTP
  99. $ pyenv install --patch 2.7.10 < <(curl -sSL http://git.io/python.patch)
  100. # applying multiple patches
  101. $ cat fix1.patch fix2.patch | pyenv install --patch 2.7.10
  102. ```
  103. ### Building with `--enable-shared`
  104. You can build CPython with `--enable-shared` to install a version with
  105. shared object.
  106. If `--enable-shared` was found in `PYTHON_CONFIGURE_OPTS` or `CONFIGURE_OPTS`,
  107. `python-build` will automatically set `RPATH` to the pyenv's prefix directory.
  108. This means you don't have to set `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` for
  109. the version(s) installed with `--enable-shared`.
  110. ```sh
  111. $ env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 2.7.9
  112. ```
  113. ### Checksum verification
  114. If you have the `shasum`, `openssl`, or `sha256sum` tool installed, python-build will
  115. automatically verify the SHA2 checksum of each downloaded package before
  116. installing it.
  117. Checksums are optional and specified as anchors on the package URL in each
  118. definition. (All bundled definitions include checksums.)
  119. ### Package download mirrors
  120. python-build will first attempt to download package files from a mirror hosted on
  121. GitHub Pages. If a package is not available on the mirror, if the mirror
  122. is down, or if the download is corrupt, python-build will fall back to the
  123. official URL specified in the definition file.
  124. You can point python-build to another mirror by specifying the
  125. `PYTHON_BUILD_MIRROR_URL` environment variable--useful if you'd like to run your
  126. own local mirror, for example. Package mirror URLs are constructed by joining
  127. this variable with the SHA2 checksum of the package file.
  128. If you don't have an SHA2 program installed, python-build will skip the download
  129. mirror and use official URLs instead. You can force python-build to bypass the
  130. mirror by setting the `PYTHON_BUILD_SKIP_MIRROR` environment variable.
  131. The official python-build download mirror is provided by
  132. [GitHub Pages](http://yyuu.github.io/pythons/).
  133. ### Package download caching
  134. You can instruct python-build to keep a local cache of downloaded package files
  135. by setting the `PYTHON_BUILD_CACHE_PATH` environment variable. When set, package
  136. files will be kept in this directory after the first successful download and
  137. reused by subsequent invocations of `python-build` and `pyenv install`.
  138. The `pyenv install` command defaults this path to `~/.pyenv/cache`, so in most
  139. cases you can enable download caching simply by creating that directory.
  140. ### Keeping the build directory after installation
  141. Both `python-build` and `pyenv install` accept the `-k` or `--keep` flag, which
  142. tells python-build to keep the downloaded source after installation. This can be
  143. useful if you need to use `gdb` and `memprof` with Python.
  144. Source code will be kept in a parallel directory tree `~/.pyenv/sources` when
  145. using `--keep` with the `pyenv install` command. You should specify the
  146. location of the source code with the `PYTHON_BUILD_BUILD_PATH` environment
  147. variable when using `--keep` with `python-build`.
  148. ## Getting Help
  149. Please see the [pyenv wiki](https://github.com/pyenv/pyenv/wiki) for solutions to common problems.
  150. [wiki]: https://github.com/pyenv/pyenv/wiki
  151. If you can't find an answer on the wiki, open an issue on the [issue
  152. tracker](https://github.com/pyenv/pyenv/issues). Be sure to include
  153. the full build log for build failures.