Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

709 wiersze
27 KiB

12 lat temu
12 lat temu
12 lat temu
12 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
12 lat temu
12 lat temu
12 lat temu
12 lat temu
11 lat temu
11 lat temu
11 lat temu
11 lat temu
12 lat temu
13 lat temu
  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. pyenv lets you easily switch between multiple versions of Python. It's
  4. simple, unobtrusive, and follows the UNIX tradition of single-purpose
  5. tools that do one thing well.
  6. This project was forked from [rbenv](https://github.com/rbenv/rbenv) and
  7. [ruby-build](https://github.com/rbenv/ruby-build), and modified for Python.
  8. ![Terminal output example](/terminal_output.png)
  9. ### What pyenv _does..._
  10. * Lets you **change the global Python version** on a per-user basis.
  11. * Provides support for **per-project Python versions**.
  12. * Allows you to **override the Python version** with an environment
  13. variable.
  14. * Searches for commands from **multiple versions of Python at a time**.
  15. This may be helpful to test across Python versions with [tox](https://pypi.python.org/pypi/tox).
  16. ### In contrast with pythonbrew and pythonz, pyenv _does not..._
  17. * **Depend on Python itself.** pyenv was made from pure shell scripts.
  18. There is no bootstrap problem of Python.
  19. * **Need to be loaded into your shell.** Instead, pyenv's shim
  20. approach works by adding a directory to your `PATH`.
  21. * **Manage virtualenv.** Of course, you can create [virtualenv](https://pypi.python.org/pypi/virtualenv)
  22. yourself, or [pyenv-virtualenv](https://github.com/pyenv/pyenv-virtualenv)
  23. to automate the process.
  24. ----
  25. ## Table of Contents
  26. * **[How It Works](#how-it-works)**
  27. * [Understanding PATH](#understanding-path)
  28. * [Understanding Shims](#understanding-shims)
  29. * [Understanding Python version selection](#understanding-python-version-selection)
  30. * [Locating Pyenv-provided Python Installations](#locating-pyenv-provided-python-installations)
  31. * **[Installation](#installation)**
  32. * [Getting Pyenv](#getting-pyenv)
  33. * [UNIX/MacOS](#unixmacos)
  34. * [Homebrew in macOS](#homebrew-in-macos)
  35. * [Automatic installer](#automatic-installer)
  36. * [Basic GitHub Checkout](#basic-github-checkout)
  37. * [Windows](#windows)
  38. * [Set up your shell environment for Pyenv](#set-up-your-shell-environment-for-pyenv)
  39. * [Restart your shell](#restart-your-shell)
  40. * [Install Python build dependencies](#install-python-build-dependencies)
  41. * **[Usage](#usage)**
  42. * [Install additional Python versions](#install-additional-python-versions)
  43. * [Prefix auto-resolution to the latest version](#prefix-auto-resolution-to-the-latest-version)
  44. * [Python versions with extended support](#python-versions-with-extended-support)
  45. * [Switch between Python versions](#switch-between-python-versions)
  46. * [Uninstall Python versions](#uninstall-python-versions)
  47. * [Other operations](#other-operations)
  48. * [Upgrading](#upgrading)
  49. * [Upgrading with Homebrew](#upgrading-with-homebrew)
  50. * [Upgrading with Installer or Git checkout](#upgrading-with-installer-or-git-checkout)
  51. * [Uninstalling pyenv](#uninstalling-pyenv)
  52. * [Pyenv plugins](#pyenv-plugins)
  53. * [Advanced Configuration](#advanced-configuration)
  54. * [Using Pyenv without shims](#using-pyenv-without-shims)
  55. * [Environment variables](#environment-variables)
  56. * **[Development](#development)**
  57. * [Contributing](#contributing)
  58. * [Version History](#version-history)
  59. * [License](#license)
  60. ----
  61. ## How It Works
  62. At a high level, pyenv intercepts Python commands using shim
  63. executables injected into your `PATH`, determines which Python version
  64. has been specified by your application, and passes your commands along
  65. to the correct Python installation.
  66. ### Understanding PATH
  67. When you run a command like `python` or `pip`, your operating system
  68. searches through a list of directories to find an executable file with
  69. that name. This list of directories lives in an environment variable
  70. called `PATH`, with each directory in the list separated by a colon:
  71. /usr/local/bin:/usr/bin:/bin
  72. Directories in `PATH` are searched from left to right, so a matching
  73. executable in a directory at the beginning of the list takes
  74. precedence over another one at the end. In this example, the
  75. `/usr/local/bin` directory will be searched first, then `/usr/bin`,
  76. then `/bin`.
  77. ### Understanding Shims
  78. pyenv works by inserting a directory of _shims_ at the front of your
  79. `PATH`:
  80. $(pyenv root)/shims:/usr/local/bin:/usr/bin:/bin
  81. Through a process called _rehashing_, pyenv maintains shims in that
  82. directory to match every Python command across every installed version
  83. of Python—`python`, `pip`, and so on.
  84. Shims are lightweight executables that simply pass your command along
  85. to pyenv. So with pyenv installed, when you run, say, `pip`, your
  86. operating system will do the following:
  87. * Search your `PATH` for an executable file named `pip`
  88. * Find the pyenv shim named `pip` at the beginning of your `PATH`
  89. * Run the shim named `pip`, which in turn passes the command along to
  90. pyenv
  91. ### Understanding Python version selection
  92. When you execute a shim, pyenv determines which Python version to use by
  93. reading it from the following sources, in this order:
  94. 1. The `PYENV_VERSION` environment variable (if specified). You can use
  95. the [`pyenv shell`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) command to set this environment
  96. variable in your current shell session.
  97. 2. The application-specific `.python-version` file in the current
  98. directory (if present). You can modify the current directory's
  99. `.python-version` file with the [`pyenv local`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local)
  100. command.
  101. 3. The first `.python-version` file found (if any) by searching each parent
  102. directory, until reaching the root of your filesystem.
  103. 4. The global `$(pyenv root)/version` file. You can modify this file using
  104. the [`pyenv global`](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-global) command.
  105. If the global version file is not present, pyenv assumes you want to use the "system"
  106. Python (see below).
  107. A special version name "`system`" means to use whatever Python is found on `PATH`
  108. after the shims `PATH` entry (in other words, whatever would be run if Pyenv
  109. shims weren't on `PATH`). Note that Pyenv considers those installations outside
  110. its control and does not attempt to inspect or distinguish them in any way.
  111. So e.g. if you are on MacOS and have OS-bundled Python 3.8.9 and Homebrew-installed
  112. Python 3.9.12 and 3.10.2 -- for Pyenv, this is still a single "`system`" version,
  113. and whichever of those is first on `PATH` under the executable name you
  114. specified will be run.
  115. **NOTE:** You can activate multiple versions at the same time, including multiple
  116. versions of Python2 or Python3 simultaneously. This allows for parallel usage of
  117. Python2 and Python3, and is required with tools like `tox`. For example, to instruct
  118. Pyenv to first use your system Python and Python3 (which are e.g. 2.7.9 and 3.4.2)
  119. but also have Python 3.3.6, 3.2.1, and 2.5.2 available, you first `pyenv install`
  120. the missing versions, then set `pyenv global system 3.3.6 3.2.1 2.5.2`.
  121. Then you'll be able to invoke any of those versions with an appropriate `pythonX` or
  122. `pythonX.Y` name.
  123. You can also specify multiple versions in a `.python-version` file by hand,
  124. separated by newlines. Lines starting with a `#` are ignored.
  125. [`pyenv which <command>`](COMMANDS.md#pyenv-which) displays which real executable would be
  126. run when you invoke `<command>` via a shim.
  127. E.g. if you have 3.3.6, 3.2.1 and 2.5.2 installed of which 3.3.6 and 2.5.2 are selected
  128. and your system Python is 3.2.5,
  129. `pyenv which python2.5` should display `$(pyenv root)/versions/2.5.2/bin/python2.5`,
  130. `pyenv which python3` -- `$(pyenv root)/versions/3.3.6/bin/python3` and
  131. `pyenv which python3.2` -- path to your system Python due to the fall-through (see below).
  132. Shims also fall through to anything further on `PATH` if the corresponding executable is
  133. not present in any of the selected Python installations.
  134. This allows you to use any programs installed elsewhere on the system as long as
  135. they are not shadowed by a selected Python installation.
  136. ### Locating Pyenv-provided Python installations
  137. Once pyenv has determined which version of Python your application has
  138. specified, it passes the command along to the corresponding Python
  139. installation.
  140. Each Python version is installed into its own directory under
  141. `$(pyenv root)/versions`.
  142. For example, you might have these versions installed:
  143. * `$(pyenv root)/versions/2.7.8/`
  144. * `$(pyenv root)/versions/3.4.2/`
  145. * `$(pyenv root)/versions/pypy-2.4.0/`
  146. As far as Pyenv is concerned, version names are simply directories under
  147. `$(pyenv root)/versions`.
  148. ----
  149. ## Installation
  150. ### Getting Pyenv
  151. #### UNIX/MacOS
  152. ##### Homebrew in macOS
  153. 1. Consider installing with [Homebrew](https://brew.sh):
  154. ```sh
  155. brew update
  156. brew install pyenv
  157. ```
  158. 2. Then follow the rest of the post-installation steps, starting with
  159. [Set up your shell environment for Pyenv](#set-up-your-shell-environment-for-pyenv).
  160. 3. OPTIONAL. To fix `brew doctor`'s warning _""config" scripts exist outside your system or Homebrew directories"_
  161. If you're going to build Homebrew formulae from source that link against Python
  162. like Tkinter or NumPy
  163. _(This is only generally the case if you are a developer of such a formula,
  164. or if you have an EOL version of MacOS for which prebuilt bottles are no longer provided
  165. and you are using such a formula)._
  166. To avoid them accidentally linking against a Pyenv-provided Python,
  167. add the following line into your interactive shell's configuration:
  168. * Bash/Zsh:
  169. ~~~bash
  170. alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
  171. ~~~
  172. * Fish:
  173. ~~~fish
  174. alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"
  175. ~~~
  176. ##### Automatic installer
  177. `curl https://pyenv.run | bash`
  178. For more details visit our other project:
  179. https://github.com/pyenv/pyenv-installer
  180. ##### Basic GitHub Checkout
  181. This will get you going with the latest version of Pyenv and make it
  182. easy to fork and contribute any changes back upstream.
  183. * **Check out Pyenv where you want it installed.**
  184. A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else):
  185. ```
  186. git clone https://github.com/pyenv/pyenv.git ~/.pyenv
  187. ```
  188. * Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't
  189. worry if it fails; Pyenv will still work normally:
  190. ```
  191. cd ~/.pyenv && src/configure && make -C src
  192. ```
  193. #### Windows
  194. Pyenv does not officially support Windows and does not work in Windows outside
  195. the Windows Subsystem for Linux.
  196. Moreover, even there, the Pythons it installs are not native Windows versions
  197. but rather Linux versions running in a virtual machine --
  198. so you won't get Windows-specific functionality.
  199. If you're in Windows, we recommend using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork --
  200. which does install native Windows Python versions.
  201. ### Set up your shell environment for Pyenv
  202. **Upgrade note:** The startup logic and instructions have been updated for simplicity in 2.3.0.
  203. The previous, more complicated configuration scheme for 2.0.0-2.2.5 still works.
  204. * Define environment variable `PYENV_ROOT` to point to the path where
  205. Pyenv will store its data. `$HOME/.pyenv` is the default.
  206. If you installed Pyenv via Git checkout, we recommend
  207. to set it to the same location as where you cloned it.
  208. * Add the `pyenv` executable to your `PATH` if it's not already there
  209. * run `eval "$(pyenv init -)"` to install `pyenv` into your shell as a shell function, enable shims and autocompletion
  210. * You may run `eval "$(pyenv init --path)"` instead to just enable shims, without shell integration
  211. The below setup should work for the vast majority of users for common use cases.
  212. See [Advanced configuration](#advanced-configuration) for details and more configuration options.
  213. - For **bash**:
  214. Stock Bash startup files vary widely between distributions in which of them source
  215. which, under what circumstances, in what order and what additional configuration they perform.
  216. As such, the most reliable way to get Pyenv in all environments is to append Pyenv
  217. configuration commands to both `.bashrc` (for interactive shells)
  218. and the profile file that Bash would use (for login shells).
  219. First, add the commands to `~/.bashrc` by running the following in your terminal:
  220. ~~~ bash
  221. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
  222. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
  223. echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  224. ~~~
  225. Then, if you have `~/.profile`, `~/.bash_profile` or `~/.bash_login`, add the commands there as well.
  226. If you have none of these, add them to `~/.profile`.
  227. * to add to `~/.profile`:
  228. ~~~ bash
  229. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
  230. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
  231. echo 'eval "$(pyenv init -)"' >> ~/.profile
  232. ~~~
  233. * to add to `~/.bash_profile`:
  234. ~~~ bash
  235. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  236. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  237. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  238. ~~~
  239. - For **Zsh**:
  240. ~~~ zsh
  241. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
  242. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
  243. echo 'eval "$(pyenv init -)"' >> ~/.zshrc
  244. ~~~
  245. If you wish to get Pyenv in noninteractive login shells as well, also add the commands to `~/.zprofile` or `~/.zlogin`.
  246. - For **Fish shell**:
  247. If you have Fish 3.2.0 or newer, execute this interactively:
  248. ~~~ fish
  249. set -Ux PYENV_ROOT $HOME/.pyenv
  250. fish_add_path $PYENV_ROOT/bin
  251. ~~~
  252. Otherwise, execute the snippet below:
  253. ~~~ fish
  254. set -Ux PYENV_ROOT $HOME/.pyenv
  255. set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths
  256. ~~~
  257. Now, add this to `~/.config/fish/config.fish`:
  258. ~~~ fish
  259. pyenv init - | source
  260. ~~~
  261. **Bash warning**: There are some systems where the `BASH_ENV` variable is configured
  262. to point to `.bashrc`. On such systems, you should almost certainly put the
  263. `eval "$(pyenv init -)"` line into `.bash_profile`, and **not** into `.bashrc`. Otherwise, you
  264. may observe strange behaviour, such as `pyenv` getting into an infinite loop.
  265. See [#264](https://github.com/pyenv/pyenv/issues/264) for details.
  266. **Proxy note**: If you use a proxy, export `http_proxy` and `https_proxy`, too.
  267. In MacOS, you might also want to install [Fig](https://fig.io/) which
  268. provides alternative shell completions for many command line tools with an
  269. IDE-like popup interface in the terminal window.
  270. (Note that their completions are independent from Pyenv's codebase
  271. so they might be slightly out of sync for bleeding-edge interface changes.)
  272. ### Restart your shell
  273. for the `PATH` changes to take effect.
  274. ```sh
  275. exec "$SHELL"
  276. ```
  277. ### Install Python build dependencies
  278. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment)
  279. before attempting to install a new Python version.
  280. You can now begin using Pyenv.
  281. ----
  282. ## Usage
  283. ### Install additional Python versions
  284. To install additional Python versions, use [`pyenv install`](COMMANDS.md#pyenv-install).
  285. For example, to download and install Python 3.10.4, run:
  286. ```sh
  287. pyenv install 3.10.4
  288. ```
  289. Running `pyenv install -l` gives the list of all available versions.
  290. **NOTE:** Most Pyenv-provided Python releases are source releases and are built
  291. from source as part of installation (that's why you need Python build dependencies preinstalled).
  292. You can pass options to Python's `configure` and compiler flags to customize the build,
  293. see [_Special environment variables_ in Python-Build's README](plugins/python-build/README.md#special-environment-variables)
  294. for details.
  295. **NOTE:** If you are having trouble installing a Python version,
  296. please visit the wiki page about
  297. [Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems).
  298. **NOTE:** If you want to use proxy for download, please set the `http_proxy` and `https_proxy`
  299. environment variables.
  300. **NOTE:** If you'd like a faster interpreter at the cost of longer build times,
  301. see [_Building for maximum performance_ in Python-Build's README](plugins/python-build/README.md#building-for-maximum-performance).
  302. #### Prefix auto-resolution to the latest version
  303. All Pyenv subcommands except `uninstall` automatically resolve full prefixes to the latest version in the corresponding version line.
  304. `pyenv install` picks the latest known version, while other subcommands pick the latest installed version.
  305. E.g. to install and then switch to the latest 3.10 release:
  306. ```sh
  307. pyenv install 3.10
  308. pyenv global 3.10
  309. ```
  310. You can run [`pyenv latest -k <prefix>`](COMMANDS.md#pyenv-latest) to see how `pyenv install` would resolve a specific prefix, or [`pyenv latest <prefix>`](COMMANDS.md#pyenv-latest) to see how other subcommands would resolve it.
  311. See the [`pyenv latest` documentation](COMMANDS.md#pyenv-latest) for details.
  312. #### Python versions with extended support
  313. For the following Python releases, Pyenv applies user-provided patches that add support for some newer environments.
  314. Though we don't actively maintain those patches, since existing releases never change,
  315. it's safe to assume that they will continue working until there are further incompatible changes
  316. in a later version of those environments.
  317. * *3.7.8-3.7.15, 3.8.4-3.8.12, 3.9.0-3.9.7* : XCode 13.3
  318. * *3.5.10, 3.6.15* : MacOS 11+ and XCode 13.3
  319. * *2.7.18* : MacOS 10.15+ and Apple Silicon
  320. ### Switch between Python versions
  321. To select a Pyenv-installed Python as the version to use, run one
  322. of the following commands:
  323. * [`pyenv shell <version>`](COMMANDS.md#pyenv-shell) -- select just for current shell session
  324. * [`pyenv local <version>`](COMMANDS.md#pyenv-local) -- automatically select whenever you are in the current directory (or its subdirectories)
  325. * [`pyenv global <version>`](COMMANDS.md#pyenv-shell) -- select globally for your user account
  326. E.g. to select the above-mentioned newly-installed Python 3.10.4 as your preferred version to use:
  327. ~~~bash
  328. pyenv global 3.10.4
  329. ~~~
  330. Now whenever you invoke `python`, `pip` etc., an executable from the Pyenv-provided
  331. 3.10.4 installation will be run instead of the system Python.
  332. Using "`system`" as a version name would reset the selection to your system-provided Python.
  333. See [Understanding shims](#understanding-shims) and
  334. [Understanding Python version selection](#understanding-python-version-selection)
  335. for more details on how the selection works and more information on its usage.
  336. ### Uninstall Python versions
  337. As time goes on, you will accumulate Python versions in your
  338. `$(pyenv root)/versions` directory.
  339. To remove old Python versions, use [`pyenv uninstall <versions>`](COMMANDS.md#pyenv-uninstall).
  340. Alternatively, you can simply `rm -rf` the directory of the version you want
  341. to remove. You can find the directory of a particular Python version
  342. with the `pyenv prefix` command, e.g. `pyenv prefix 2.6.8`.
  343. Note however that plugins may run additional operations on uninstall
  344. which you would need to do by hand as well. E.g. Pyenv-Virtualenv also
  345. removes any virtual environments linked to the version being uninstalled.
  346. ### Other operations
  347. Run `pyenv commands` to get a list of all available subcommands.
  348. Run a subcommand with `--help` to get help on it, or see the [Commands Reference](COMMANDS.md).
  349. Note that Pyenv plugins that you install may add their own subcommands.
  350. ## Upgrading
  351. ### Upgrading with Homebrew
  352. If you've installed Pyenv using Homebrew, upgrade using:
  353. ```sh
  354. brew upgrade pyenv
  355. ```
  356. To switch from a release to the latest development version of Pyenv, use:
  357. ```sh
  358. brew uninstall pyenv
  359. brew install pyenv --head
  360. ```
  361. then you can upgrade it with `brew upgrade pyenv` as usual.
  362. ### Upgrading with Installer or Git checkout
  363. If you've installed Pyenv with Pyenv-installer, you likely have the
  364. [Pyenv-Update](https://github.com/pyenv/pyenv-update) plugin that would
  365. upgrade Pyenv and all installed plugins:
  366. ```sh
  367. pyenv update
  368. ```
  369. If you've installed Pyenv using Pyenv-installer or Git checkout, you can also
  370. upgrade your installation at any time using Git.
  371. To upgrade to the latest development version of pyenv, use `git pull`:
  372. ```sh
  373. cd $(pyenv root)
  374. git pull
  375. ```
  376. To upgrade to a specific release of Pyenv, check out the corresponding tag:
  377. ```sh
  378. cd $(pyenv root)
  379. git fetch
  380. git tag
  381. git checkout v0.1.0
  382. ```
  383. ## Uninstalling pyenv
  384. The simplicity of pyenv makes it easy to temporarily disable it, or
  385. uninstall from the system.
  386. 1. To **disable** Pyenv managing your Python versions, simply remove the
  387. `pyenv init` invocations from your shell startup configuration. This will
  388. remove Pyenv shims directory from `PATH`, and future invocations like
  389. `python` will execute the system Python version, as it was before Pyenv.
  390. `pyenv` will still be accessible on the command line, but your Python
  391. apps won't be affected by version switching.
  392. 2. To completely **uninstall** Pyenv, remove _all_ Pyenv configuration lines
  393. from your shell startup configuration, and then remove
  394. its root directory. This will **delete all Python versions** that were
  395. installed under the `` $(pyenv root)/versions/ `` directory:
  396. ```sh
  397. rm -rf $(pyenv root)
  398. ```
  399. If you've installed Pyenv using a package manager, as a final step,
  400. perform the Pyenv package removal. For instance, for Homebrew:
  401. ```
  402. brew uninstall pyenv
  403. ```
  404. ## Pyenv plugins
  405. Pyenv provides a simple, flexible and maintainable way to extend and customize its functionality with plugins --
  406. as simple as creating a plugin directory and dropping a shell script on a certain subpath of it
  407. with whatever extra logic you need to be run at certain moments.
  408. See [_Plugins_ on the wiki](https://github.com/pyenv/pyenv/wiki/Plugins) on how to install and use plugins
  409. as well as a catalog of some useful existing plugins for common needs.
  410. See [_Authoring plugins_ on the wiki](https://github.com/pyenv/pyenv/wiki/Authoring-plugins) on writing your own plugins.
  411. ## Advanced Configuration
  412. Skip this section unless you must know what every line in your shell
  413. profile is doing.
  414. Also see the [Environment variables](#environment-variables) section
  415. for the environment variables that control Pyenv's behavior.
  416. `pyenv init` is the only command that crosses the line of loading
  417. extra commands into your shell. Coming from RVM, some of you might be
  418. opposed to this idea. Here's what `eval "$(pyenv init -)"` actually does:
  419. 1. **Sets up the shims path.** This is what allows Pyenv to intercept
  420. and redirect invocations of `python`, `pip` etc. transparently.
  421. It prepends `$(pyenv root)/shims` to your `$PATH`.
  422. It also deletes any other instances of `$(pyenv root)/shims` on `PATH`
  423. which allows to invoke `eval "$(pyenv init -)"` multiple times without
  424. getting duplicate `PATH` entries.
  425. 2. **Installs autocompletion.** This is entirely optional but pretty
  426. useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
  427. up. There are also completions for Zsh and Fish.
  428. 3. **Rehashes shims.** From time to time you'll need to rebuild your
  429. shim files. Doing this on init makes sure everything is up to
  430. date. You can always run `pyenv rehash` manually.
  431. 4. **Installs `pyenv` into the current shell as a shell function.**
  432. This bit is also optional, but allows
  433. pyenv and plugins to change variables in your current shell.
  434. This is required for some commands like `pyenv shell` to work.
  435. The sh dispatcher doesn't do
  436. anything crazy like override `cd` or hack your shell prompt, but if
  437. for some reason you need `pyenv` to be a real script rather than a
  438. shell function, you can safely skip it.
  439. `eval "$(pyenv init --path)"` only does items 1 and 3.
  440. To see exactly what happens under the hood for yourself, run `pyenv init -`
  441. or `pyenv init --path`.
  442. `eval "$(pyenv init -)"` is supposed to run at any interactive shell's
  443. startup (including nested shells -- e.g. those invoked from editors)
  444. so that you get completion and convenience shell functions.
  445. `eval "$(pyenv init --path)"` can be used instead of `eval "$(pyenv init -)"`
  446. to just enable shims, without shell integration. It can also be used to bump shims
  447. to the front of `PATH` after some other logic has prepended stuff to `PATH`
  448. that may shadow Pyenv's shims.
  449. * In particular, in Debian-based distributions, the stock `~/.profile`
  450. prepends per-user `bin` directories to `PATH` after having sourced `~/.bashrc`.
  451. This necessitates appending a `pyenv init` call to `~/.profile` as well as `~/.bashrc`
  452. in these distributions because the system's Pip places executables for
  453. modules installed by a non-root user into those per-user `bin` directories.
  454. ### Using Pyenv without shims
  455. If you don't want to use `pyenv init` and shims, you can still benefit
  456. from pyenv's ability to install Python versions for you. Just run
  457. `pyenv install` and you will find versions installed in
  458. `$(pyenv root)/versions`.
  459. You can manually execute or symlink them as required,
  460. or you can use [`pyenv exec <command>`](COMMANDS.md#pyenv-exec)
  461. whenever you want `<command>` to be affected by Pyenv's version selection
  462. as currently configured.
  463. `pyenv exec` works by prepending `$(pyenv root)/versions/<selected version>/bin`
  464. to `PATH` in the `<command>`'s environment, the same as what e.g. RVM does.
  465. ### Environment variables
  466. You can affect how Pyenv operates with the following environment variables:
  467. name | default | description
  468. -----|---------|------------
  469. `PYENV_VERSION` | | Specifies the Python version to be used.<br>Also see [`pyenv shell`](COMMANDS.md#pyenv-shell)
  470. `PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see [`pyenv root`](COMMANDS.md#pyenv-root)
  471. `PYENV_DEBUG` | | Outputs debug information.<br>Also as: `pyenv --debug <subcommand>`
  472. `PYENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for pyenv hooks.
  473. `PYENV_DIR` | `$PWD` | Directory to start searching for `.python-version` files.
  474. `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
  475. See also [_Special environment variables_ in Python-Build's README](plugins/python-build/README.md#special-environment-variables)
  476. for environment variables that can be used to customize the build.
  477. ----
  478. ## Development
  479. The pyenv source code is [hosted on
  480. GitHub](https://github.com/pyenv/pyenv). It's clean, modular,
  481. and easy to understand, even if you're not a shell hacker.
  482. Tests are executed using [Bats](https://github.com/bats-core/bats-core):
  483. bats test
  484. bats/test/<file>.bats
  485. ### Contributing
  486. Feel free to submit pull requests and file bugs on the [issue
  487. tracker](https://github.com/pyenv/pyenv/issues).
  488. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on submitting changes.
  489. ### Version History
  490. See [CHANGELOG.md](CHANGELOG.md).
  491. ### License
  492. [The MIT License](LICENSE)
  493. [pyenv-virtualenv]: https://github.com/pyenv/pyenv-virtualenv#readme
  494. [hooks]: https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks