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

712 рядки
27 KiB

9 роки тому
12 роки тому
12 роки тому
11 роки тому
12 роки тому
12 роки тому
10 роки тому
11 роки тому
10 роки тому
2 роки тому
10 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
7 роки тому
9 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
2 роки тому
2 роки тому
2 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
13 роки тому
  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 shell (bash / zshrc / ...)
  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. If you want to install (and update to) the latest development head of Pyenv
  159. rather than the latest release, instead run:
  160. ```sh
  161. brew install pyenv --head
  162. ```
  163. 3. Then follow the rest of the post-installation steps, starting with
  164. [Set up your shell environment for Pyenv](#set-up-your-shell-environment-for-pyenv).
  165. 4. OPTIONAL. To fix `brew doctor`'s warning _""config" scripts exist outside your system or Homebrew directories"_
  166. If you're going to build Homebrew formulae from source that link against Python
  167. like Tkinter or NumPy
  168. _(This is only generally the case if you are a developer of such a formula,
  169. or if you have an EOL version of MacOS for which prebuilt bottles are no longer provided
  170. and you are using such a formula)._
  171. To avoid them accidentally linking against a Pyenv-provided Python,
  172. add the following line into your interactive shell's configuration:
  173. * Bash/Zsh:
  174. ~~~bash
  175. alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew'
  176. ~~~
  177. * Fish:
  178. ~~~fish
  179. alias brew="env PATH=(string replace (pyenv root)/shims '' \"\$PATH\") brew"
  180. ~~~
  181. ##### Automatic installer
  182. ```bash
  183. curl https://pyenv.run | bash
  184. ```
  185. For more details visit our other project:
  186. https://github.com/pyenv/pyenv-installer
  187. ##### Basic GitHub Checkout
  188. This will get you going with the latest version of Pyenv and make it
  189. easy to fork and contribute any changes back upstream.
  190. * **Check out Pyenv where you want it installed.**
  191. A good place to choose is `$HOME/.pyenv` (but you can install it somewhere else):
  192. ```
  193. git clone https://github.com/pyenv/pyenv.git ~/.pyenv
  194. ```
  195. * Optionally, try to compile a dynamic Bash extension to speed up Pyenv. Don't
  196. worry if it fails; Pyenv will still work normally:
  197. ```
  198. cd ~/.pyenv && src/configure && make -C src
  199. ```
  200. #### Windows
  201. Pyenv does not officially support Windows and does not work in Windows outside
  202. the Windows Subsystem for Linux.
  203. Moreover, even there, the Pythons it installs are not native Windows versions
  204. but rather Linux versions running in a virtual machine --
  205. so you won't get Windows-specific functionality.
  206. If you're in Windows, we recommend using @kirankotari's [`pyenv-win`](https://github.com/pyenv-win/pyenv-win) fork --
  207. which does install native Windows Python versions.
  208. ### Set up your shell environment for Pyenv
  209. **Upgrade note:** The startup logic and instructions have been updated for simplicity in 2.3.0.
  210. The previous, more complicated configuration scheme for 2.0.0-2.2.5 still works.
  211. * Define environment variable `PYENV_ROOT` to point to the path where
  212. Pyenv will store its data. `$HOME/.pyenv` is the default.
  213. If you installed Pyenv via Git checkout, we recommend
  214. to set it to the same location as where you cloned it.
  215. * Add the `pyenv` executable to your `PATH` if it's not already there
  216. * run `eval "$(pyenv init -)"` to install `pyenv` into your shell as a shell function, enable shims and autocompletion
  217. * You may run `eval "$(pyenv init --path)"` instead to just enable shims, without shell integration
  218. The below setup should work for the vast majority of users for common use cases.
  219. See [Advanced configuration](#advanced-configuration) for details and more configuration options.
  220. - For **bash**:
  221. Stock Bash startup files vary widely between distributions in which of them source
  222. which, under what circumstances, in what order and what additional configuration they perform.
  223. As such, the most reliable way to get Pyenv in all environments is to append Pyenv
  224. configuration commands to both `.bashrc` (for interactive shells)
  225. and the profile file that Bash would use (for login shells).
  226. First, add the commands to `~/.bashrc` by running the following in your terminal:
  227. ~~~ bash
  228. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
  229. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
  230. echo 'eval "$(pyenv init -)"' >> ~/.bashrc
  231. ~~~
  232. Then, if you have `~/.profile`, `~/.bash_profile` or `~/.bash_login`, add the commands there as well.
  233. If you have none of these, add them to `~/.profile`.
  234. * to add to `~/.profile`:
  235. ~~~ bash
  236. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
  237. echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
  238. echo 'eval "$(pyenv init -)"' >> ~/.profile
  239. ~~~
  240. * to add to `~/.bash_profile`:
  241. ~~~ bash
  242. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
  243. echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
  244. echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
  245. ~~~
  246. - For **Zsh**:
  247. ~~~ zsh
  248. echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
  249. echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
  250. echo 'eval "$(pyenv init -)"' >> ~/.zshrc
  251. ~~~
  252. If you wish to get Pyenv in noninteractive login shells as well, also add the commands to `~/.zprofile` or `~/.zlogin`.
  253. - For **Fish shell**:
  254. If you have Fish 3.2.0 or newer, execute this interactively:
  255. ~~~ fish
  256. set -Ux PYENV_ROOT $HOME/.pyenv
  257. fish_add_path $PYENV_ROOT/bin
  258. ~~~
  259. Otherwise, execute the snippet below:
  260. ~~~ fish
  261. set -Ux PYENV_ROOT $HOME/.pyenv
  262. set -U fish_user_paths $PYENV_ROOT/bin $fish_user_paths
  263. ~~~
  264. Now, add this to `~/.config/fish/config.fish`:
  265. ~~~ fish
  266. pyenv init - | source
  267. ~~~
  268. **Bash warning**: There are some systems where the `BASH_ENV` variable is configured
  269. to point to `.bashrc`. On such systems, you should almost certainly put the
  270. `eval "$(pyenv init -)"` line into `.bash_profile`, and **not** into `.bashrc`. Otherwise, you
  271. may observe strange behaviour, such as `pyenv` getting into an infinite loop.
  272. See [#264](https://github.com/pyenv/pyenv/issues/264) for details.
  273. **Proxy note**: If you use a proxy, export `http_proxy` and `https_proxy`, too.
  274. ### Restart your shell
  275. for the `PATH` changes to take effect.
  276. ```sh
  277. exec "$SHELL"
  278. ```
  279. ### Install Python build dependencies
  280. [**Install Python build dependencies**](https://github.com/pyenv/pyenv/wiki#suggested-build-environment)
  281. before attempting to install a new Python version.
  282. You can now begin using Pyenv.
  283. ----
  284. ## Usage
  285. ### Install additional Python versions
  286. To install additional Python versions, use [`pyenv install`](COMMANDS.md#pyenv-install).
  287. For example, to download and install Python 3.10.4, run:
  288. ```sh
  289. pyenv install 3.10.4
  290. ```
  291. Running `pyenv install -l` gives the list of all available versions.
  292. **NOTE:** Most Pyenv-provided Python releases are source releases and are built
  293. from source as part of installation (that's why you need Python build dependencies preinstalled).
  294. You can pass options to Python's `configure` and compiler flags to customize the build,
  295. see [_Special environment variables_ in Python-Build's README](plugins/python-build/README.md#special-environment-variables)
  296. for details.
  297. **NOTE:** If you are having trouble installing a Python version,
  298. please visit the wiki page about
  299. [Common Build Problems](https://github.com/pyenv/pyenv/wiki/Common-build-problems).
  300. **NOTE:** If you want to use proxy for download, please set the `http_proxy` and `https_proxy`
  301. environment variables.
  302. **NOTE:** If you'd like a faster interpreter at the cost of longer build times,
  303. see [_Building for maximum performance_ in Python-Build's README](plugins/python-build/README.md#building-for-maximum-performance).
  304. #### Prefix auto-resolution to the latest version
  305. All Pyenv subcommands except `uninstall` automatically resolve full prefixes to the latest version in the corresponding version line.
  306. `pyenv install` picks the latest known version, while other subcommands pick the latest installed version.
  307. E.g. to install and then switch to the latest 3.10 release:
  308. ```sh
  309. pyenv install 3.10
  310. pyenv global 3.10
  311. ```
  312. 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.
  313. See the [`pyenv latest` documentation](COMMANDS.md#pyenv-latest) for details.
  314. #### Python versions with extended support
  315. For the following Python releases, Pyenv applies user-provided patches that add support for some newer environments.
  316. Though we don't actively maintain those patches, since existing releases never change,
  317. it's safe to assume that they will continue working until there are further incompatible changes
  318. in a later version of those environments.
  319. * *3.7.8-3.7.15, 3.8.4-3.8.12, 3.9.0-3.9.7* : XCode 13.3
  320. * *3.5.10, 3.6.15* : MacOS 11+ and XCode 13.3
  321. * *2.7.18* : MacOS 10.15+ and Apple Silicon
  322. ### Switch between Python versions
  323. To select a Pyenv-installed Python as the version to use, run one
  324. of the following commands:
  325. * [`pyenv shell <version>`](COMMANDS.md#pyenv-shell) -- select just for current shell session
  326. * [`pyenv local <version>`](COMMANDS.md#pyenv-local) -- automatically select whenever you are in the current directory (or its subdirectories)
  327. * [`pyenv global <version>`](COMMANDS.md#pyenv-shell) -- select globally for your user account
  328. E.g. to select the above-mentioned newly-installed Python 3.10.4 as your preferred version to use:
  329. ~~~bash
  330. pyenv global 3.10.4
  331. ~~~
  332. Now whenever you invoke `python`, `pip` etc., an executable from the Pyenv-provided
  333. 3.10.4 installation will be run instead of the system Python.
  334. Using "`system`" as a version name would reset the selection to your system-provided Python.
  335. See [Understanding shims](#understanding-shims) and
  336. [Understanding Python version selection](#understanding-python-version-selection)
  337. for more details on how the selection works and more information on its usage.
  338. ### Uninstall Python versions
  339. As time goes on, you will accumulate Python versions in your
  340. `$(pyenv root)/versions` directory.
  341. To remove old Python versions, use [`pyenv uninstall <versions>`](COMMANDS.md#pyenv-uninstall).
  342. Alternatively, you can simply `rm -rf` the directory of the version you want
  343. to remove. You can find the directory of a particular Python version
  344. with the `pyenv prefix` command, e.g. `pyenv prefix 2.6.8`.
  345. Note however that plugins may run additional operations on uninstall
  346. which you would need to do by hand as well. E.g. Pyenv-Virtualenv also
  347. removes any virtual environments linked to the version being uninstalled.
  348. ### Other operations
  349. Run `pyenv commands` to get a list of all available subcommands.
  350. Run a subcommand with `--help` to get help on it, or see the [Commands Reference](COMMANDS.md).
  351. Note that Pyenv plugins that you install may add their own subcommands.
  352. ## Upgrading
  353. ### Upgrading with Homebrew
  354. If you've installed Pyenv using Homebrew, upgrade using:
  355. ```sh
  356. brew upgrade pyenv
  357. ```
  358. To switch from a release to the latest development head of Pyenv, use:
  359. ```sh
  360. brew uninstall pyenv
  361. brew install pyenv --head
  362. ```
  363. then you can upgrade it with `brew upgrade pyenv` as usual.
  364. ### Upgrading with Installer or Git checkout
  365. If you've installed Pyenv with Pyenv-installer, you likely have the
  366. [Pyenv-Update](https://github.com/pyenv/pyenv-update) plugin that would
  367. upgrade Pyenv and all installed plugins:
  368. ```sh
  369. pyenv update
  370. ```
  371. If you've installed Pyenv using Pyenv-installer or Git checkout, you can also
  372. upgrade your installation at any time using Git.
  373. To upgrade to the latest development version of pyenv, use `git pull`:
  374. ```sh
  375. cd $(pyenv root)
  376. git pull
  377. ```
  378. To upgrade to a specific release of Pyenv, check out the corresponding tag:
  379. ```sh
  380. cd $(pyenv root)
  381. git fetch
  382. git tag
  383. git checkout v0.1.0
  384. ```
  385. ## Uninstalling pyenv
  386. The simplicity of pyenv makes it easy to temporarily disable it, or
  387. uninstall from the system.
  388. 1. To **disable** Pyenv managing your Python versions, simply remove the
  389. `pyenv init` invocations from your shell startup configuration. This will
  390. remove Pyenv shims directory from `PATH`, and future invocations like
  391. `python` will execute the system Python version, as it was before Pyenv.
  392. `pyenv` will still be accessible on the command line, but your Python
  393. apps won't be affected by version switching.
  394. 2. To completely **uninstall** Pyenv, remove _all_ Pyenv configuration lines
  395. from your shell startup configuration, and then remove
  396. its root directory. This will **delete all Python versions** that were
  397. installed under the `` $(pyenv root)/versions/ `` directory:
  398. ```sh
  399. rm -rf $(pyenv root)
  400. ```
  401. If you've installed Pyenv using a package manager, as a final step,
  402. perform the Pyenv package removal. For instance, for Homebrew:
  403. ```
  404. brew uninstall pyenv
  405. ```
  406. ## Pyenv plugins
  407. Pyenv provides a simple way to extend and customize its functionality with plugins --
  408. as simple as creating a plugin directory and dropping a shell script on a certain subpath of it
  409. with whatever extra logic you need to be run at certain moments.
  410. The main idea is that most things that you can put under `$PYENV_ROOT/<whatever>` you can also put
  411. under `$PYENV_ROOT/plugins/your_plugin_name/<whatever>`.
  412. See [_Plugins_ on the wiki](https://github.com/pyenv/pyenv/wiki/Plugins) on how to install and use plugins
  413. as well as a catalog of some useful existing plugins for common needs.
  414. See [_Authoring plugins_ on the wiki](https://github.com/pyenv/pyenv/wiki/Authoring-plugins) on writing your own plugins.
  415. ## Advanced Configuration
  416. Skip this section unless you must know what every line in your shell
  417. profile is doing.
  418. Also see the [Environment variables](#environment-variables) section
  419. for the environment variables that control Pyenv's behavior.
  420. `pyenv init` is the only command that crosses the line of loading
  421. extra commands into your shell. Coming from RVM, some of you might be
  422. opposed to this idea. Here's what `eval "$(pyenv init -)"` actually does:
  423. 1. **Sets up the shims path.** This is what allows Pyenv to intercept
  424. and redirect invocations of `python`, `pip` etc. transparently.
  425. It prepends `$(pyenv root)/shims` to your `$PATH`.
  426. It also deletes any other instances of `$(pyenv root)/shims` on `PATH`
  427. which allows to invoke `eval "$(pyenv init -)"` multiple times without
  428. getting duplicate `PATH` entries.
  429. 2. **Installs autocompletion.** This is entirely optional but pretty
  430. useful. Sourcing `$(pyenv root)/completions/pyenv.bash` will set that
  431. up. There are also completions for Zsh and Fish.
  432. 3. **Rehashes shims.** From time to time you'll need to rebuild your
  433. shim files. Doing this on init makes sure everything is up to
  434. date. You can always run `pyenv rehash` manually.
  435. 4. **Installs `pyenv` into the current shell as a shell function.**
  436. This bit is also optional, but allows
  437. pyenv and plugins to change variables in your current shell.
  438. This is required for some commands like `pyenv shell` to work.
  439. The sh dispatcher doesn't do
  440. anything crazy like override `cd` or hack your shell prompt, but if
  441. for some reason you need `pyenv` to be a real script rather than a
  442. shell function, you can safely skip it.
  443. `eval "$(pyenv init --path)"` only does items 1 and 3.
  444. To see exactly what happens under the hood for yourself, run `pyenv init -`
  445. or `pyenv init --path`.
  446. `eval "$(pyenv init -)"` is supposed to run at any interactive shell's
  447. startup (including nested shells -- e.g. those invoked from editors)
  448. so that you get completion and convenience shell functions.
  449. `eval "$(pyenv init --path)"` can be used instead of `eval "$(pyenv init -)"`
  450. to just enable shims, without shell integration. It can also be used to bump shims
  451. to the front of `PATH` after some other logic has prepended stuff to `PATH`
  452. that may shadow Pyenv's shims.
  453. * In particular, in Debian-based distributions, the stock `~/.profile`
  454. prepends per-user `bin` directories to `PATH` after having sourced `~/.bashrc`.
  455. This necessitates appending a `pyenv init` call to `~/.profile` as well as `~/.bashrc`
  456. in these distributions because the system's Pip places executables for
  457. modules installed by a non-root user into those per-user `bin` directories.
  458. ### Using Pyenv without shims
  459. If you don't want to use `pyenv init` and shims, you can still benefit
  460. from pyenv's ability to install Python versions for you. Just run
  461. `pyenv install` and you will find versions installed in
  462. `$(pyenv root)/versions`.
  463. You can manually execute or symlink them as required,
  464. or you can use [`pyenv exec <command>`](COMMANDS.md#pyenv-exec)
  465. whenever you want `<command>` to be affected by Pyenv's version selection
  466. as currently configured.
  467. `pyenv exec` works by prepending `$(pyenv root)/versions/<selected version>/bin`
  468. to `PATH` in the `<command>`'s environment, the same as what e.g. RVM does.
  469. ### Environment variables
  470. You can affect how Pyenv operates with the following environment variables:
  471. name | default | description
  472. -----|---------|------------
  473. `PYENV_VERSION` | | Specifies the Python version to be used.<br>Also see [`pyenv shell`](COMMANDS.md#pyenv-shell)
  474. `PYENV_ROOT` | `~/.pyenv` | Defines the directory under which Python versions and shims reside.<br>Also see [`pyenv root`](COMMANDS.md#pyenv-root)
  475. `PYENV_DEBUG` | | Outputs debug information.<br>Also as: `pyenv --debug <subcommand>`
  476. `PYENV_HOOK_PATH` | [_see wiki_][hooks] | Colon-separated list of paths searched for pyenv hooks.
  477. `PYENV_DIR` | `$PWD` | Directory to start searching for `.python-version` files.
  478. See also [_Special environment variables_ in Python-Build's README](plugins/python-build/README.md#special-environment-variables)
  479. for environment variables that can be used to customize the build.
  480. ----
  481. ## Development
  482. The pyenv source code is [hosted on
  483. GitHub](https://github.com/pyenv/pyenv). It's clean, modular,
  484. and easy to understand, even if you're not a shell hacker.
  485. Tests are executed using [Bats](https://github.com/bats-core/bats-core):
  486. bats test
  487. bats/test/<file>.bats
  488. ### Contributing
  489. Feel free to submit pull requests and file bugs on the [issue
  490. tracker](https://github.com/pyenv/pyenv/issues).
  491. See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on submitting changes.
  492. ### Version History
  493. See [CHANGELOG.md](CHANGELOG.md).
  494. ### License
  495. [The MIT License](LICENSE)
  496. [pyenv-virtualenv]: https://github.com/pyenv/pyenv-virtualenv#readme
  497. [hooks]: https://github.com/pyenv/pyenv/wiki/Authoring-plugins#pyenv-hooks