Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

455 rindas
15 KiB

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