You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

372 lines
10 KiB

  1. # Command Reference
  2. Like `git`, the `pyenv` command delegates to subcommands based on its
  3. first argument.
  4. The most common subcommands are:
  5. * [`pyenv help`](#pyenv-help)
  6. * [`pyenv commands`](#pyenv-commands)
  7. * [`pyenv local`](#pyenv-local)
  8. * [`pyenv global`](#pyenv-global)
  9. * [`pyenv shell`](#pyenv-shell)
  10. * [`pyenv install`](#pyenv-install)
  11. * [`pyenv uninstall`](#pyenv-uninstall)
  12. * [`pyenv rehash`](#pyenv-rehash)
  13. * [`pyenv version`](#pyenv-version)
  14. * [`pyenv versions`](#pyenv-versions)
  15. * [`pyenv which`](#pyenv-which)
  16. * [`pyenv whence`](#pyenv-whence)
  17. * [`pyenv exec`](#pyenv-exec)
  18. * [`pyenv root`](#pyenv-root)
  19. * [`pyenv prefix`](#pyenv-prefix)
  20. * [`pyenv hooks`](#pyenv-hooks)
  21. * [`pyenv shims`](#pyenv-shims)
  22. * [`pyenv init`](#pyenv-init)
  23. * [`pyenv completions`](#pyenv-completions)
  24. ## `pyenv help`
  25. List all available pyenv commands along with a brief description of what they do. Run `pyenv help <command>` for information on a specific command. For full documentation, see: https://github.com/pyenv/pyenv#readme
  26. ## `pyenv commands`
  27. Lists all available pyenv commands.
  28. ## `pyenv local`
  29. Sets a local application-specific Python version by writing the version
  30. name to a `.python-version` file in the current directory. This version
  31. overrides the global version, and can be overridden itself by setting
  32. the `PYENV_VERSION` environment variable or with the `pyenv shell`
  33. command.
  34. $ pyenv local 2.7.6
  35. When run without a version number, `pyenv local` reports the currently
  36. configured local version. You can also unset the local version:
  37. $ pyenv local --unset
  38. Previous versions of pyenv stored local version specifications in a
  39. file named `.pyenv-version`. For backwards compatibility, pyenv will
  40. read a local version specified in an `.pyenv-version` file, but a
  41. `.python-version` file in the same directory will take precedence.
  42. ### `pyenv local` (advanced)
  43. You can specify multiple versions as local Python at once.
  44. Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
  45. $ pyenv local 2.7.6 3.3.3
  46. $ pyenv versions
  47. system
  48. * 2.7.6 (set by /Users/yyuu/path/to/project/.python-version)
  49. * 3.3.3 (set by /Users/yyuu/path/to/project/.python-version)
  50. $ python --version
  51. Python 2.7.6
  52. $ python2.7 --version
  53. Python 2.7.6
  54. $ python3.3 --version
  55. Python 3.3.3
  56. or, if you prefer 3.3.3 over 2.7.6,
  57. $ pyenv local 3.3.3 2.7.6
  58. $ pyenv versions
  59. system
  60. * 2.7.6 (set by /Users/yyuu/path/to/project/.python-version)
  61. * 3.3.3 (set by /Users/yyuu/path/to/project/.python-version)
  62. venv27
  63. $ python --version
  64. Python 3.3.3
  65. $ python2.7 --version
  66. Python 2.7.6
  67. $ python3.3 --version
  68. Python 3.3.3
  69. ## `pyenv global`
  70. Sets the global version of Python to be used in all shells by writing
  71. the version name to the `~/.pyenv/version` file. This version can be
  72. overridden by an application-specific `.python-version` file, or by
  73. setting the `PYENV_VERSION` environment variable.
  74. $ pyenv global 2.7.6
  75. The special version name `system` tells pyenv to use the system Python
  76. (detected by searching your `$PATH`).
  77. When run without a version number, `pyenv global` reports the
  78. currently configured global version.
  79. ### `pyenv global` (advanced)
  80. You can specify multiple versions as global Python at once.
  81. Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
  82. $ pyenv global 2.7.6 3.3.3
  83. $ pyenv versions
  84. system
  85. * 2.7.6 (set by /Users/yyuu/.pyenv/version)
  86. * 3.3.3 (set by /Users/yyuu/.pyenv/version)
  87. $ python --version
  88. Python 2.7.6
  89. $ python2.7 --version
  90. Python 2.7.6
  91. $ python3.3 --version
  92. Python 3.3.3
  93. or, if you prefer 3.3.3 over 2.7.6,
  94. $ pyenv global 3.3.3 2.7.6
  95. $ pyenv versions
  96. system
  97. * 2.7.6 (set by /Users/yyuu/.pyenv/version)
  98. * 3.3.3 (set by /Users/yyuu/.pyenv/version)
  99. venv27
  100. $ python --version
  101. Python 3.3.3
  102. $ python2.7 --version
  103. Python 2.7.6
  104. $ python3.3 --version
  105. Python 3.3.3
  106. ## `pyenv shell`
  107. Sets a shell-specific Python version by setting the `PYENV_VERSION`
  108. environment variable in your shell. This version overrides
  109. application-specific versions and the global version.
  110. $ pyenv shell pypy-2.2.1
  111. When run without a version number, `pyenv shell` reports the current
  112. value of `PYENV_VERSION`. You can also unset the shell version:
  113. $ pyenv shell --unset
  114. Note that you'll need pyenv's shell integration enabled (step 3 of
  115. the installation instructions) in order to use this command. If you
  116. prefer not to use shell integration, you may simply set the
  117. `PYENV_VERSION` variable yourself:
  118. $ export PYENV_VERSION=pypy-2.2.1
  119. ### `pyenv shell` (advanced)
  120. You can specify multiple versions via `PYENV_VERSION` at once.
  121. Let's say if you have two versions of 2.7.6 and 3.3.3. If you prefer 2.7.6 over 3.3.3,
  122. $ pyenv shell 2.7.6 3.3.3
  123. $ pyenv versions
  124. system
  125. * 2.7.6 (set by PYENV_VERSION environment variable)
  126. * 3.3.3 (set by PYENV_VERSION environment variable)
  127. $ python --version
  128. Python 2.7.6
  129. $ python2.7 --version
  130. Python 2.7.6
  131. $ python3.3 --version
  132. Python 3.3.3
  133. or, if you prefer 3.3.3 over 2.7.6,
  134. $ pyenv shell 3.3.3 2.7.6
  135. $ pyenv versions
  136. system
  137. * 2.7.6 (set by PYENV_VERSION environment variable)
  138. * 3.3.3 (set by PYENV_VERSION environment variable)
  139. venv27
  140. $ python --version
  141. Python 3.3.3
  142. $ python2.7 --version
  143. Python 2.7.6
  144. $ python3.3 --version
  145. Python 3.3.3
  146. ## `pyenv install`
  147. Install a Python version (using [`python-build`](https://github.com/pyenv/pyenv/tree/master/plugins/python-build)).
  148. Usage: pyenv install [-f] [-kvp] <version>
  149. pyenv install [-f] [-kvp] <definition-file>
  150. pyenv install -l|--list
  151. -l/--list List all available versions
  152. -f/--force Install even if the version appears to be installed already
  153. -s/--skip-existing Skip the installation if the version appears to be installed already
  154. python-build options:
  155. -k/--keep Keep source tree in $PYENV_BUILD_ROOT after installation
  156. (defaults to $PYENV_ROOT/sources)
  157. -v/--verbose Verbose mode: print compilation status to stdout
  158. -p/--patch Apply a patch from stdin before building
  159. -g/--debug Build a debug version
  160. To list the all available versions of Python, including Anaconda, Jython, pypy, and stackless, use:
  161. $ pyenv install --list
  162. Then install the desired versions:
  163. $ pyenv install 2.7.6
  164. $ pyenv install 2.6.8
  165. $ pyenv versions
  166. system
  167. 2.6.8
  168. * 2.7.6 (set by /home/yyuu/.pyenv/version)
  169. ## `pyenv uninstall`
  170. Uninstall a specific Python version.
  171. Usage: pyenv uninstall [-f|--force] <version>
  172. -f Attempt to remove the specified version without prompting
  173. for confirmation. If the version does not exist, do not
  174. display an error message.
  175. ## `pyenv rehash`
  176. Installs shims for all Python binaries known to pyenv (i.e.,
  177. `~/.pyenv/versions/*/bin/*`). Run this command after you install a new
  178. version of Python, or install a package that provides binaries.
  179. $ pyenv rehash
  180. ## `pyenv version`
  181. Displays the currently active Python version, along with information on
  182. how it was set.
  183. $ pyenv version
  184. 2.7.6 (set by /home/yyuu/.pyenv/version)
  185. ## `pyenv versions`
  186. Lists all Python versions known to pyenv, and shows an asterisk next to
  187. the currently active version.
  188. $ pyenv versions
  189. 2.5.6
  190. 2.6.8
  191. * 2.7.6 (set by /home/yyuu/.pyenv/version)
  192. 3.3.3
  193. jython-2.5.3
  194. pypy-2.2.1
  195. ## `pyenv which`
  196. Displays the full path to the executable that pyenv will invoke when
  197. you run the given command.
  198. $ pyenv which python3.3
  199. /home/yyuu/.pyenv/versions/3.3.3/bin/python3.3
  200. Use --nosystem argument in case when you don't need to search command in the
  201. system environment.
  202. ## `pyenv whence`
  203. Lists all Python versions with the given command installed.
  204. $ pyenv whence 2to3
  205. 2.6.8
  206. 2.7.6
  207. 3.3.3
  208. ## `pyenv exec`
  209. Usage: pyenv exec <command> [arg1 arg2...]
  210. Runs an executable by first preparing PATH so that the selected Python
  211. version's `bin` directory is at the front.
  212. For example, if the currently selected Python version is 3.9.7:
  213. pyenv exec pip install -r requirements.txt
  214. is equivalent to:
  215. PATH="$PYENV_ROOT/versions/3.9.7/bin:$PATH" pip install -r requirements.txt
  216. ## `pyenv root`
  217. Displays the root directory where versions and shims are kept.
  218. $ pyenv root
  219. /home/user/.pyenv
  220. ## `pyenv prefix`
  221. Displays the directory where a Python version is installed. If no
  222. version is given, `pyenv prefix` displays the location of the
  223. currently selected version.
  224. $ pyenv prefix 3.9.7
  225. /home/user/.pyenv/versions/3.9.7
  226. ## `pyenv hooks`
  227. Lists installed hook scripts for a given pyenv command.
  228. Usage: pyenv hooks <command>
  229. ## `pyenv shims`
  230. List existing pyenv shims.
  231. Usage: pyenv shims [--short]
  232. $ pyenv shims
  233. /home/user/.pyenv/shims/2to3
  234. /home/user/.pyenv/shims/2to3-3.9
  235. /home/user/.pyenv/shims/idle
  236. /home/user/.pyenv/shims/idle3
  237. /home/user/.pyenv/shims/idle3.9
  238. /home/user/.pyenv/shims/pip
  239. /home/user/.pyenv/shims/pip3
  240. /home/user/.pyenv/shims/pip3.9
  241. /home/user/.pyenv/shims/pydoc
  242. /home/user/.pyenv/shims/pydoc3
  243. /home/user/.pyenv/shims/pydoc3.9
  244. /home/user/.pyenv/shims/python
  245. /home/user/.pyenv/shims/python3
  246. /home/user/.pyenv/shims/python3.9
  247. /home/user/.pyenv/shims/python3.9-config
  248. /home/user/.pyenv/shims/python3.9-gdb.py
  249. /home/user/.pyenv/shims/python3-config
  250. /home/user/.pyenv/shims/python-config
  251. ## `pyenv init`
  252. Configure the shell environment for pyenv
  253. Usage: eval "$(pyenv init [-|--path] [--no-rehash] [<shell>])"
  254. - Initialize shims directory, print PYENV_SHELL variable, completions path
  255. and shell function
  256. --path Print shims path
  257. --no-rehash Add no rehash command to output
  258. ## `pyenv completions`
  259. Lists available completions for a given pyenv command.
  260. Usage: pyenv completions <command> [arg1 arg2...]