Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

477 рядки
15 KiB

12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
12 роки тому
11 роки тому
11 роки тому
  1. # Simple Python Version Management: pyenv
  2. pyenv lets you easily switch between multiple versions of Python. It's
  3. simple, unobtrusive, and follows the UNIX tradition of single-purpose
  4. tools that do one thing well.
  5. This project was forked from [rbenv](https://github.com/sstephenson/rbenv) and
  6. [ruby-build](https://github.com/sstephenson/ruby-build), and modified for Python.
  7. <img src="http://gyazo.com/9c829fafdf5e58880c820349c4e9197e.png?1346414267" width="849" height="454">
  8. ### pyenv _does..._
  9. * Let you **change the global Python version** on a per-user basis.
  10. * Provide support for **per-project Python versions**.
  11. * Allow you to **override the Python version** with an environment
  12. variable.
  13. * Search commands from **multiple versions of Python at a time**.
  14. This may be helpful to test across Python versions with [tox](http://pypi.python.org/pypi/tox).
  15. ### In contrast with pythonbrew and pythonz, pyenv _does not..._
  16. * **Depending on Python itself.** pyenv was made from pure shell scripts.
  17. There is no bootstrap problem of Python.
  18. * **Need to be loaded into your shell.** Instead, pyenv's shim
  19. approach works by adding a directory to your `$PATH`.
  20. * **Manage virtualenv.** Of course, you can create [virtualenv](http://pypi.python.org/pypi/virtualenv)
  21. yourself, or [pyenv-virtualenv](https://github.com/yyuu/pyenv-virtualenv)
  22. to automate the process.
  23. ## Table of Contents
  24. * [How It Works](#how-it-works)
  25. * [Understanding PATH](#understanding-path)
  26. * [Understanding Shims](#understanding-shims)
  27. * [Choosing the Python Version](#choosing-the-python-version)
  28. * [Locating the Python Installation](#locating-the-python-installation)
  29. * [Installation](#installation)
  30. * [Basic GitHub Checkout](#basic-github-checkout)
  31. * [Upgrading](#upgrading)
  32. * [Neckbeard Configuration](#neckbeard-configuration)
  33. * [Uninstalling Python Versions](#uninstalling-python-versions)
  34. * [Command Reference](#command-reference)
  35. * [pyenv local](#pyenv-local)
  36. * [pyenv global](#pyenv-global)
  37. * [pyenv shell](#pyenv-shell)
  38. * [pyenv versions](#pyenv-versions)
  39. * [pyenv version](#pyenv-version)
  40. * [pyenv rehash](#pyenv-rehash)
  41. * [pyenv which](#pyenv-which)
  42. * [pyenv whence](#pyenv-whence)
  43. * [Development](#development)
  44. * [Version History](#version-history)
  45. * [License](#license)
  46. ## How It Works
  47. At a high level, pyenv intercepts Python commands using shim
  48. executables injected into your `PATH`, determines which Python version
  49. has been specified by your application, and passes your commands along
  50. to the correct Python installation.
  51. ### Understanding PATH
  52. When you run a command like `python` or `pip`, your operating system
  53. searches through a list of directories to find an executable file with
  54. that name. This list of directories lives in an environment variable
  55. called `PATH`, with each directory in the list separated by a colon:
  56. /usr/local/bin:/usr/bin:/bin
  57. Directories in `PATH` are searched from left to right, so a matching
  58. executable in a directory at the beginning of the list takes
  59. precedence over another one at the end. In this example, the
  60. `/usr/local/bin` directory will be searched first, then `/usr/bin`,
  61. then `/bin`.
  62. ### Understanding Shims
  63. pyenv works by inserting a directory of _shims_ at the front of your
  64. `PATH`:
  65. ~/.pyenv/shims:/usr/local/bin:/usr/bin:/bin
  66. Through a process called _rehashing_, pyenv maintains shims in that
  67. directory to match every Python command across every installed version
  68. of Python—`python`, `pip`, and so on.
  69. Shims are lightweight executables that simply pass your command along
  70. to pyenv. So with pyenv installed, when you run, say, `pip`, your
  71. operating system will do the following:
  72. * Search your `PATH` for an executable file named `pip`
  73. * Find the pyenv shim named `pip` at the beginning of your `PATH`
  74. * Run the shim named `pip`, which in turn passes the command along to
  75. pyenv
  76. ### Choosing the Python Version
  77. When you execute a shim, pyenv determines which Python version to use by
  78. reading it from the following sources, in this order:
  79. 1. The `PYENV_VERSION` environment variable, if specified. You can use
  80. the [`pyenv shell`](#pyenv-shell) command to set this environment
  81. variable in your current shell session.
  82. 2. The application-specific `.python-version` file in the current
  83. directory, if present. You can modify the current directory's
  84. `.python-version` file with the [`pyenv local`](#pyenv-local)
  85. command.
  86. 3. The first `.python-version` file found by searching each parent
  87. directory until reaching the root of your filesystem, if any.
  88. 4. The global `~/.pyenv/version` file. You can modify this file using
  89. the [`pyenv global`](#pyenv-global) command. If the global version
  90. file is not present, pyenv assumes you want to use the "system"
  91. Python—i.e. whatever version would be run if pyenv weren't in your
  92. path.
  93. ### Locating the Python Installation
  94. Once pyenv has determined which version of Python your application has
  95. specified, it passes the command along to the corresponding Python
  96. installation.
  97. Each Python version is installed into its own directory under
  98. `~/.pyenv/versions`. For example, you might have these versions
  99. installed:
  100. * `~/.pyenv/versions/2.7.4/`
  101. * `~/.pyenv/versions/3.3.1/`
  102. * `~/.pyenv/versions/pypy-1.9/`
  103. Version names to pyenv are simply the names of the directories in
  104. `~/.pyenv/versions`.
  105. ## Installation
  106. ### Basic GitHub Checkout
  107. This will get you going with the latest version of pyenv and make it
  108. easy to fork and contribute any changes back upstream.
  109. 1. Check out pyenv into `~/.pyenv`.
  110. $ cd
  111. $ git clone git://github.com/yyuu/pyenv.git .pyenv
  112. 2. Add `~/.pyenv/bin` to your `$PATH` for access to the `pyenv`
  113. command-line utility.
  114. $ echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bash_profile
  115. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
  116. 3. Add pyenv init to your shell to enable shims and autocompletion.
  117. $ echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  118. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
  119. 4. Restart your shell so the path changes take effect. You can now
  120. begin using pyenv.
  121. $ exec $SHELL
  122. 5. Install Python versions into `~/.pyenv/versions`. For example, to
  123. install Python 2.7.4, download and unpack the source, then run:
  124. $ pyenv install 2.7.4
  125. **NOTE** If you need to pass configure option to build, please use
  126. ```CONFIGURE_OPTS``` environment variable.
  127. 6. Rebuild the shim binaries. You should do this any time you install
  128. a new Python binary (for example, when installing a new Python version,
  129. or when installing a package that provides a binary).
  130. $ pyenv rehash
  131. #### Upgrading
  132. If you've installed pyenv using the instructions above, you can
  133. upgrade your installation at any time using git.
  134. To upgrade to the latest development version of pyenv, use `git pull`:
  135. $ cd ~/.pyenv
  136. $ git pull
  137. To upgrade to a specific release of pyenv, check out the corresponding
  138. tag:
  139. $ cd ~/.pyenv
  140. $ git fetch
  141. $ git tag
  142. v0.1.0
  143. $ git checkout v0.1.0
  144. ### Neckbeard Configuration
  145. Skip this section unless you must know what every line in your shell
  146. profile is doing.
  147. `pyenv init` is the only command that crosses the line of loading
  148. extra commands into your shell. Coming from rvm, some of you might be
  149. opposed to this idea. Here's what `pyenv init` actually does:
  150. 1. Sets up your shims path. This is the only requirement for pyenv to
  151. function properly. You can do this by hand by prepending
  152. `~/.pyenv/shims` to your `$PATH`.
  153. 2. Installs autocompletion. This is entirely optional but pretty
  154. useful. Sourcing `~/.pyenv/completions/pyenv.bash` will set that
  155. up. There is also a `~/.pyenv/completions/pyenv.zsh` for Zsh
  156. users.
  157. 3. Rehashes shims. From time to time you'll need to rebuild your
  158. shim files. Doing this on init makes sure everything is up to
  159. date. You can always run `pyenv rehash` manually.
  160. 4. Installs the sh dispatcher. This bit is also optional, but allows
  161. pyenv and plugins to change variables in your current shell, making
  162. commands like `pyenv shell` possible. The sh dispatcher doesn't do
  163. anything crazy like override `cd` or hack your shell prompt, but if
  164. for some reason you need `pyenv` to be a real script rather than a
  165. shell function, you can safely skip it.
  166. Run `pyenv init -` for yourself to see exactly what happens under the
  167. hood.
  168. ### Uninstalling Python Versions
  169. As time goes on, Python versions you install will accumulate in your
  170. `~/.pyenv/versions` directory.
  171. To remove old Python versions, `pyenv uninstall` command to automate
  172. the removal process.
  173. Or, simply `rm -rf` the directory of the
  174. version you want to remove. You can find the directory of a particular
  175. Python version with the `pyenv prefix` command, e.g. `pyenv prefix
  176. 2.6.8`.
  177. ## Command Reference
  178. Like `git`, the `pyenv` command delegates to subcommands based on its
  179. first argument. The most common subcommands are:
  180. ### pyenv local
  181. Sets a local application-specific Python version by writing the version
  182. name to a `.python-version` file in the current directory. This version
  183. overrides the global version, and can be overridden itself by setting
  184. the `PYENV_VERSION` environment variable or with the `pyenv shell`
  185. command.
  186. $ pyenv local 2.7.4
  187. When run without a version number, `pyenv local` reports the currently
  188. configured local version. You can also unset the local version:
  189. $ pyenv local --unset
  190. Previous versions of pyenv stored local version specifications in a
  191. file named `.pyenv-version`. For backwards compatibility, pyenv will
  192. read a local version specified in an `.pyenv-version` file, but a
  193. `.python-version` file in the same directory will take precedence.
  194. **pyenv feature**
  195. You can specify multiple versions as local Python. Commands
  196. within these Python versions are searched by specified order.
  197. $ pyenv local 2.7.4 3.2.4
  198. $ pyenv local
  199. 2.7.4
  200. 3.2.4
  201. $ pyenv which python2.7
  202. /home/yyuu/.pyenv/versions/2.7.4/bin/python2.7
  203. $ pyenv which python3.2
  204. /home/yyuu/.pyenv/versions/3.2.4/bin/python3.2
  205. $ pyenv which python
  206. /home/yyuu/.pyenv/versions/2.7.4/bin/python
  207. You can manage your version stack by `pyenv push` and `pyenv pop`.
  208. $ pyenv local
  209. 2.7.4
  210. 3.2.4
  211. $ pyenv push 3.3.1
  212. $ pyenv local
  213. 2.7.4
  214. 3.2.4
  215. 3.3.1
  216. $ pyenv pop
  217. 2.7.4
  218. 3.2.4
  219. ### pyenv global
  220. Sets the global version of Python to be used in all shells by writing
  221. the version name to the `~/.pyenv/version` file. This version can be
  222. overridden by an application-specific `.python-version` file, or by
  223. setting the `PYENV_VERSION` environment variable.
  224. $ pyenv global 2.7.4
  225. The special version name `system` tells pyenv to use the system Python
  226. (detected by searching your `$PATH`).
  227. When run without a version number, `pyenv global` reports the
  228. currently configured global version.
  229. **pyenv feature**
  230. You can specify multiple versions as global Python. Commands
  231. within these Python versions are searched by specified order.
  232. $ pyenv global 2.7.4 3.2.4
  233. $ pyenv global
  234. 2.7.4
  235. 3.2.4
  236. $ pyenv which python2.7
  237. /home/yyuu/.pyenv/versions/2.7.4/bin/python2.7
  238. $ pyenv which python3.2
  239. /home/yyuu/.pyenv/versions/3.2.4/bin/python3.2
  240. $ pyenv which python
  241. /home/yyuu/.pyenv/versions/2.7.4/bin/python
  242. You can manage your version stack by `pyenv push` and `pyenv pop`.
  243. $ pyenv global
  244. 2.7.4
  245. 3.2.4
  246. $ pyenv push 3.3.1
  247. $ pyenv global
  248. 2.7.4
  249. 3.2.4
  250. 3.3.1
  251. $ pyenv pop
  252. 2.7.4
  253. 3.2.4
  254. ### pyenv shell
  255. Sets a shell-specific Python version by setting the `PYENV_VERSION`
  256. environment variable in your shell. This version overrides
  257. application-specific versions and the global version.
  258. $ pyenv shell pypy-1.9
  259. When run without a version number, `pyenv shell` reports the current
  260. value of `PYENV_VERSION`. You can also unset the shell version:
  261. $ pyenv shell --unset
  262. Note that you'll need pyenv's shell integration enabled (step 3 of
  263. the installation instructions) in order to use this command. If you
  264. prefer not to use shell integration, you may simply set the
  265. `PYENV_VERSION` variable yourself:
  266. $ export PYENV_VERSION=pypy-1.9
  267. **pyenv feature**
  268. You can specify multiple versions via `PYENV_VERSION`
  269. environment variable in your shell.
  270. $ pyenv shell pypy-1.9 2.7.4
  271. $ echo $PYENV_VERSION
  272. pypy-1.9:2.7.4
  273. $ pyenv version
  274. pypy-1.9 (set by PYENV_VERSION environment variable)
  275. 2.7.4 (set by PYENV_VERSION environment variable)
  276. ### pyenv versions
  277. Lists all Python versions known to pyenv, and shows an asterisk next to
  278. the currently active version.
  279. $ pyenv versions
  280. 2.5.6
  281. 2.6.8
  282. * 2.7.4 (set by /home/yyuu/.pyenv/version)
  283. 3.2.4
  284. jython-2.5.3
  285. pypy-1.9
  286. ### pyenv version
  287. Displays the currently active Python version, along with information on
  288. how it was set.
  289. $ pyenv version
  290. 2.7.4 (set by /home/yyuu/.pyenv/version)
  291. ### pyenv rehash
  292. Installs shims for all Python binaries known to pyenv (i.e.,
  293. `~/.pyenv/versions/*/bin/*`). Run this command after you install a new
  294. version of Python, or install a package that provides binaries.
  295. $ pyenv rehash
  296. ### pyenv which
  297. Displays the full path to the executable that pyenv will invoke when
  298. you run the given command.
  299. $ pyenv which python3.2
  300. /home/yyuu/.pyenv/versions/3.2.4/bin/python3.2
  301. ### pyenv whence
  302. Lists all Python versions with the given command installed.
  303. $ pyenv whence 2to3
  304. 2.6.8
  305. 2.7.4
  306. 3.2.4
  307. ## Development
  308. The pyenv source code is [hosted on
  309. GitHub](https://github.com/yyuu/pyenv). It's clean, modular,
  310. and easy to understand, even if you're not a shell hacker.
  311. Please feel free to submit pull requests and file bugs on the [issue
  312. tracker](https://github.com/yyuu/pyenv/issues).
  313. ### Version History
  314. **0.2.0** (February 18, 2013)
  315. * Import changes from rbenv 0.4.0.
  316. **0.1.2** (October 23, 2012)
  317. * Add push/pop for version stack management.
  318. * Support multiple versions via environment variable.
  319. * Now GCC is not a requirement to build CPython and Stackless.
  320. **0.1.1** (September 3, 2012)
  321. * Support multiple versions of Python at a time.
  322. **0.1.0** (August 31, 2012)
  323. * Initial public release.
  324. ### License
  325. (The MIT license)
  326. * Copyright (c) 2013 Yamashita, Yuu
  327. * Copyright (c) 2013 Sam Stephenson
  328. Permission is hereby granted, free of charge, to any person obtaining
  329. a copy of this software and associated documentation files (the
  330. "Software"), to deal in the Software without restriction, including
  331. without limitation the rights to use, copy, modify, merge, publish,
  332. distribute, sublicense, and/or sell copies of the Software, and to
  333. permit persons to whom the Software is furnished to do so, subject to
  334. the following conditions:
  335. The above copyright notice and this permission notice shall be
  336. included in all copies or substantial portions of the Software.
  337. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  338. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  339. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  340. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  341. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  342. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  343. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.