Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

439 lignes
17 KiB

il y a 9 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 11 ans
il y a 12 ans
il y a 12 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 7 ans
il y a 11 ans
il y a 9 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 7 ans
il y a 11 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 12 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 11 ans
il y a 12 ans
il y a 13 ans
il y a 13 ans
  1. # Simple Python Version Management: pyenv
  2. [![Join the chat at https://gitter.im/yyuu/pyenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/yyuu/pyenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  3. [![Build Status](https://travis-ci.org/pyenv/pyenv.svg?branch=master)](https://travis-ci.org/pyenv/pyenv)
  4. pyenv lets you easily switch between multiple versions of Python. It's
  5. simple, unobtrusive, and follows the UNIX tradition of single-purpose
  6. tools that do one thing well.
  7. This project was forked from [rbenv](https://github.com/rbenv/rbenv) and
  8. [ruby-build](https://github.com/rbenv/ruby-build), and modified for Python.
  9. ![Terminal output example](/terminal_output.png)
  10. ### pyenv _does..._
  11. * Let you **change the global Python version** on a per-user basis.
  12. * Provide support for **per-project Python versions**.
  13. * Allow you to **override the Python version** with an environment
  14. variable.
  15. * Search commands from **multiple versions of Python at a time**.
  16. This may be helpful to test across Python versions with [tox](https://pypi.python.org/pypi/tox).
  17. ### In contrast with pythonbrew and pythonz, pyenv _does not..._
  18. * **Depend on Python itself.** pyenv was made from pure shell scripts.
  19. There is no bootstrap problem of Python.
  20. * **Need to be loaded into your shell.** Instead, pyenv's shim
  21. approach works by adding a directory to your `$PATH`.
  22. * **Manage virtualenv.** Of course, you can create [virtualenv](https://pypi.python.org/pypi/virtualenv)
  23. yourself, or [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)
  24. to automate the process.
  25. ----
  26. ## Table of Contents
  27. * **[How It Works](#how-it-works)**
  28. * [Understanding PATH](#understanding-path)
  29. * [Understanding Shims](#understanding-shims)
  30. * [Choosing the Python Version](#choosing-the-python-version)
  31. * [Locating the Python Installation](#locating-the-python-installation)
  32. * **[Installation](#installation)**
  33. * [Basic GitHub Checkout](#basic-github-checkout)
  34. * [Upgrading](#upgrading)
  35. * [Homebrew on macOS](#homebrew-on-macos)
  36. * [Advanced Configuration](#advanced-configuration)
  37. * [Uninstalling Python Versions](#uninstalling-python-versions)
  38. * **[Command Reference](#command-reference)**
  39. * **[Development](#development)**
  40. * [Version History](#version-history)
  41. * [License](#license)
  42. ----
  43. ## How It Works
  44. At a high level, pyenv intercepts Python commands using shim
  45. executables injected into your `PATH`, determines which Python version
  46. has been specified by your application, and passes your commands along
  47. to the correct Python installation.
  48. ### Understanding PATH
  49. When you run a command like `python` or `pip`, your operating system
  50. searches through a list of directories to find an executable file with
  51. that name. This list of directories lives in an environment variable
  52. called `PATH`, with each directory in the list separated by a colon:
  53. /usr/local/bin:/usr/bin:/bin
  54. Directories in `PATH` are searched from left to right, so a matching
  55. executable in a directory at the beginning of the list takes
  56. precedence over another one at the end. In this example, the
  57. `/usr/local/bin` directory will be searched first, then `/usr/bin`,
  58. then `/bin`.
  59. ### Understanding Shims
  60. pyenv works by inserting a directory of _shims_ at the front of your
  61. `PATH`:
  62. $(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
  63. Through a process called _rehashing_, pyenv maintains shims in that
  64. directory to match every Python command across every installed version
  65. of Python—`python`, `pip`, and so on.
  66. Shims are lightweight executables that simply pass your command along
  67. to pyenv. So with pyenv installed, when you run, say, `pip`, your
  68. operating system will do the following:
  69. * Search your `PATH` for an executable file named `pip`
  70. * Find the pyenv shim named `pip` at the beginning of your `PATH`
  71. * Run the shim named `pip`, which in turn passes the command along to
  72. pyenv
  73. ### Choosing the Python Version
  74. When you execute a shim, pyenv determines which Python version to use by
  75. reading it from the following sources, in this order:
  76. 1. The `PYENV_VERSION` environment variable (if specified). You can use
  77. the [`pyenv shell`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) command to set this environment
  78. variable in your current shell session.
  79. 2. The application-specific `.python-version` file in the current
  80. directory (if present). You can modify the current directory's
  81. `.python-version` file with the [`pyenv local`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local)
  82. command.
  83. 3. The first `.python-version` file found (if any) by searching each parent
  84. directory, until reaching the root of your filesystem.
  85. 4. The global `$(pyenv root)/version` file. You can modify this file using
  86. the [`pyenv global`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global) command. If the global version
  87. file is not present, pyenv assumes you want to use the "system"
  88. Python. (In other words, whatever version would run if pyenv weren't in your
  89. `PATH`.)
  90. **NOTE:** You can activate multiple versions at the same time, including multiple
  91. versions of Python2 or Python3 simultaneously. This allows for parallel usage of
  92. Python2 and Python3, and is required with tools like `tox`. For example, to set
  93. your path to first use your `system` Python and Python3 (set to 2.7.9 and 3.4.2
  94. in this example), but also have Python 3.3.6, 3.2, and 2.5 available on your
  95. `PATH`, one would first `pyenv install` the missing versions, then set `pyenv
  96. global system 3.3.6 3.2 2.5`. At this point, one should be able to find the full
  97. executable path to each of these using `pyenv which`, e.g. `pyenv which python2.5`
  98. (should display `$(pyenv root)/versions/2.5/bin/python2.5`), or `pyenv which
  99. python3.4` (should display path to system Python3). You can also specify multiple
  100. versions in a `.python-version` file, separated by newlines or any whitespace.
  101. ### Locating the Python Installation
  102. Once pyenv has determined which version of Python your application has
  103. specified, it passes the command along to the corresponding Python
  104. installation.
  105. Each Python version is installed into its own directory under
  106. `$(pyenv root)/versions`.
  107. For example, you might have these versions installed:
  108. * `$(pyenv root)/versions/2.7.8/`
  109. * `$(pyenv root)/versions/3.4.2/`
  110. * `$(pyenv root)/versions/pypy-2.4.0/`
  111. As far as pyenv is concerned, version names are simply the directories in
  112. `$(pyenv root)/versions`.
  113. ### Managing Virtual Environments
  114. There is a pyenv plugin named [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv) which comes with various features to help pyenv users to manage virtual environments created by virtualenv or Anaconda.
  115. Because the `activate` script of those virtual environments are relying on mutating `$PATH` variable of user's interactive shell, it will intercept pyenv's shim style command execution hooks.
  116. We'd recommend to install pyenv-virtualenv as well if you have some plan to play with those virtual environments.
  117. ----
  118. ## Installation
  119. ### Prerequisites:
  120. For pyenv to install python correctly you should [**install the Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment).
  121. ### Homebrew on macOS
  122. 1. Consider installing with [Homebrew](https://brew.sh)
  123. ```sh
  124. brew update
  125. brew install pyenv
  126. ```
  127. 2. Then follow the rest of the post-installation steps under [Basic GitHub Checkout](https://github.com/pyenv/pyenv#basic-github-checkout), starting with #3 ("Add `pyenv init` to your shell to enable shims and autocompletion").
  128. If you're on Windows, consider using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork. (`pyenv` does not work on windows outside the Windows Subsystem for Linux)
  129. ### The automatic installer
  130. Visit my other project:
  131. https://github.com/pyenv/pyenv-installer
  132. ### Basic GitHub Checkout
  133. This will get you going with the latest version of pyenv and make it
  134. easy to fork and contribute any changes back upstream.
  135. 1. **Check out pyenv where you want it installed.**
  136. A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else).
  137. git clone https://github.com/pyenv/pyenv.git ~/.pyenv
  138. Optionally, try to compile dynamic bash extension to speed up pyenv. Don't
  139. worry if it fails; pyenv will still work normally:
  140. cd ~/.pyenv && src/configure && make -C src
  141. 2. **Define environment variable `PYENV_ROOT`** to point to the path where
  142. pyenv repo is cloned and add `$PYENV_ROOT/bin` to your `$PATH` for access
  143. to the `pyenv` command-line utility.
  144. - For **bash**:
  145. ~~~ bash
  146. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  147. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  148. ~~~
  149. - For **Ubuntu Desktop**:
  150. ~~~ bash
  151. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
  152. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
  153. ~~~
  154. - For **Zsh**:
  155. ~~~ zsh
  156. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
  157. echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
  158. ~~~
  159. - For **Fish shell**:
  160. ~~~ fish
  161. set -Ux PYENV_ROOT $HOME/.pyenv
  162. set -Ux fish_user_paths $PYENV_ROOT/bin $fish_user_paths
  163. ~~~
  164. - **Proxy note**: If you use a proxy, export `http_proxy` and `HTTPS_PROXY` too.
  165. 3. **Add `pyenv init` to your shell** to enable shims and autocompletion.
  166. Please make sure `eval "$(pyenv init -)"` is placed toward the end of the shell
  167. configuration file since it manipulates `PATH` during the initialization.
  168. - For **bash**:
  169. ~~~ bash
  170. echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bash_profile
  171. ~~~
  172. - For **Ubuntu Desktop** and **Fedora**:
  173. ~~~ bash
  174. echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
  175. ~~~
  176. - For **Zsh**:
  177. ~~~ zsh
  178. echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.zshrc
  179. ~~~
  180. - For **Fish shell**:
  181. ~~~ fish
  182. echo -e '\n\n# pyenv init\nif command -v pyenv 1>/dev/null 2>&1\n pyenv init - | source\nend' >> ~/.config/fish/config.fish
  183. ~~~
  184. **General warning**: There are some systems where the `BASH_ENV` variable is configured
  185. to point to `.bashrc`. On such systems you should almost certainly put the above mentioned line
  186. `eval "$(pyenv init -)"` into `.bash_profile`, and **not** into `.bashrc`. Otherwise you
  187. may observe strange behaviour, such as `pyenv` getting into an infinite loop.
  188. See [#264](https://github.com/pyenv/pyenv/issues/264) for details.
  189. 4. **Restart your shell so the path changes take effect.**
  190. You can now begin using pyenv.
  191. ```sh
  192. exec "$SHELL"
  193. ```
  194. 5. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment) before attempting to install a new Python version.
  195. 6. **Install Python versions into `$(pyenv root)/versions`.**
  196. For example, to download and install Python 2.7.8, run:
  197. ```sh
  198. pyenv install 2.7.8
  199. ```
  200. **NOTE:** If you need to pass configure option to build, please use
  201. ```CONFIGURE_OPTS``` environment variable.
  202. **NOTE:** If you want to use proxy to download, please use `http_proxy` and `https_proxy`
  203. environment variable.
  204. **NOTE:** If you are having trouble installing a python version,
  205. please visit the wiki page about
  206. [Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems)
  207. #### Upgrading
  208. If you've installed pyenv using homebrew, upgrade using:
  209. ```sh
  210. brew upgrade pyenv
  211. ```
  212. If you've installed pyenv using the instructions above, you can
  213. upgrade your installation at any time using git.
  214. To upgrade to the latest development version of pyenv, use `git pull`:
  215. ```sh
  216. cd $(pyenv root)
  217. git pull
  218. ```
  219. To upgrade to a specific release of pyenv, check out the corresponding tag:
  220. ```sh
  221. cd $(pyenv root)
  222. git fetch
  223. git tag
  224. git checkout v0.1.0
  225. ```
  226. ### Uninstalling pyenv
  227. The simplicity of pyenv makes it easy to temporarily disable it, or
  228. uninstall from the system.
  229. 1. To **disable** pyenv managing your Python versions, simply remove the
  230. `pyenv init` line from your shell startup configuration. This will
  231. remove pyenv shims directory from PATH, and future invocations like
  232. `python` will execute the system Python version, as before pyenv.
  233. `pyenv` will still be accessible on the command line, but your Python
  234. apps won't be affected by version switching.
  235. 2. To completely **uninstall** pyenv, perform step (1) and then remove
  236. its root directory. This will **delete all Python versions** that were
  237. installed under `` $(pyenv root)/versions/ `` directory:
  238. ```sh
  239. rm -rf $(pyenv root)
  240. ```
  241. If you've installed pyenv using a package manager, as a final step
  242. perform the pyenv package removal. For instance, for Homebrew:
  243. brew uninstall pyenv
  244. ### Advanced Configuration
  245. Skip this section unless you must know what every line in your shell
  246. profile is doing.
  247. `pyenv init` is the only command that crosses the line of loading
  248. extra commands into your shell. Coming from rvm, some of you might be
  249. opposed to this idea. Here's what `pyenv init` actually does:
  250. 1. **Sets up your shims path.** This is the only requirement for pyenv to
  251. function properly. You can do this by hand by prepending
  252. `$(pyenv root)/shims` to your `$PATH`.
  253. 2. **Installs autocompletion.** This is entirely optional but pretty
  254. useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
  255. up. There is also a `$(pyenv root)/completions/pyenv.zsh` for Zsh
  256. users.
  257. 3. **Rehashes shims.** From time to time you'll need to rebuild your
  258. shim files. Doing this on init makes sure everything is up to
  259. date. You can always run `pyenv rehash` manually.
  260. 4. **Installs the sh dispatcher.** This bit is also optional, but allows
  261. pyenv and plugins to change variables in your current shell, making
  262. commands like `pyenv shell` possible. The sh dispatcher doesn't do
  263. anything crazy like override `cd` or hack your shell prompt, but if
  264. for some reason you need `pyenv` to be a real script rather than a
  265. shell function, you can safely skip it.
  266. To see exactly what happens under the hood for yourself, run `pyenv init -`.
  267. If you don't want to use `pyenv init` and shims, you can still benefit
  268. from pyenv's ability to install Python versions for you. Just run
  269. `pyenv install` and you will find versions installed in
  270. `$(pyenv root)/versions`, which you can manually execute or symlink
  271. as required.
  272. ### Uninstalling Python Versions
  273. As time goes on, you will accumulate Python versions in your
  274. `$(pyenv root)/versions` directory.
  275. To remove old Python versions, `pyenv uninstall` command to automate
  276. the removal process.
  277. Alternatively, simply `rm -rf` the directory of the version you want
  278. to remove. You can find the directory of a particular Python version
  279. with the `pyenv prefix` command, e.g. `pyenv prefix 2.6.8`.
  280. ----
  281. ## Command Reference
  282. See [COMMANDS.md](COMMANDS.md).
  283. ----
  284. ## Environment variables
  285. You can affect how pyenv operates with the following settings:
  286. name | default | description
  287. -----|---------|------------
  288. `PYENV_VERSION` | | Specifies the Python version to be used.<br>Also see [`pyenv shell`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell)
  289. `PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see `pyenv root`
  290. `PYENV_DEBUG` | | Outputs debug information.<br>Also as: `pyenv --debug <subcommand>`
  291. `PYENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for pyenv hooks.
  292. `PYENV_DIR` | `$PWD` | Directory to start searching for `.python-version` files.
  293. `PYTHON_BUILD_ARIA2_OPTS` | | Used to pass additional parameters to [`aria2`](https://aria2.github.io/).<br>If the `aria2c` binary is available on PATH, pyenv uses `aria2c` instead of `curl` or `wget` to download the Python Source code. If you have an unstable internet connection, you can use this variable to instruct `aria2` to accelerate the download.<br>In most cases, you will only need to use `-x 10 -k 1M` as value to `PYTHON_BUILD_ARIA2_OPTS` environment variable
  294. ## Development
  295. The pyenv source code is [hosted on
  296. GitHub](https://github.com/pyenv/pyenv). It's clean, modular,
  297. and easy to understand, even if you're not a shell hacker.
  298. Tests are executed using [Bats](https://github.com/bats-core/bats-core):
  299. bats test
  300. bats/test/<file>.bats
  301. Please feel free to submit pull requests and file bugs on the [issue
  302. tracker](https://github.com/pyenv/pyenv/issues).
  303. [pyenv-virtualenv]: https://github.com/pyenv/pyenv-virtualenv#readme
  304. [hooks]: https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks
  305. ### Version History
  306. See [CHANGELOG.md](CHANGELOG.md).
  307. ### License
  308. [The MIT License](LICENSE)