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.

380 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. To install the latest version of Python without giving a specific version use the `:latest` syntax. For example, to install the latest patch version for Python 3.8 you could do:
  170. pyenv install 3.8:latest
  171. To install the latest major release for Python 3 try:
  172. pyenv install 3:latest
  173. ## `pyenv uninstall`
  174. Uninstall a specific Python version.
  175. Usage: pyenv uninstall [-f|--force] <version>
  176. -f Attempt to remove the specified version without prompting
  177. for confirmation. If the version does not exist, do not
  178. display an error message.
  179. ## `pyenv rehash`
  180. Installs shims for all Python binaries known to pyenv (i.e.,
  181. `~/.pyenv/versions/*/bin/*`). Run this command after you install a new
  182. version of Python, or install a package that provides binaries.
  183. $ pyenv rehash
  184. ## `pyenv version`
  185. Displays the currently active Python version, along with information on
  186. how it was set.
  187. $ pyenv version
  188. 2.7.6 (set by /home/yyuu/.pyenv/version)
  189. ## `pyenv versions`
  190. Lists all Python versions known to pyenv, and shows an asterisk next to
  191. the currently active version.
  192. $ pyenv versions
  193. 2.5.6
  194. 2.6.8
  195. * 2.7.6 (set by /home/yyuu/.pyenv/version)
  196. 3.3.3
  197. jython-2.5.3
  198. pypy-2.2.1
  199. ## `pyenv which`
  200. Displays the full path to the executable that pyenv will invoke when
  201. you run the given command.
  202. $ pyenv which python3.3
  203. /home/yyuu/.pyenv/versions/3.3.3/bin/python3.3
  204. Use --nosystem argument in case when you don't need to search command in the
  205. system environment.
  206. ## `pyenv whence`
  207. Lists all Python versions with the given command installed.
  208. $ pyenv whence 2to3
  209. 2.6.8
  210. 2.7.6
  211. 3.3.3
  212. ## `pyenv exec`
  213. Usage: pyenv exec <command> [arg1 arg2...]
  214. Runs an executable by first preparing PATH so that the selected Python
  215. version's `bin` directory is at the front.
  216. For example, if the currently selected Python version is 3.9.7:
  217. pyenv exec pip install -r requirements.txt
  218. is equivalent to:
  219. PATH="$PYENV_ROOT/versions/3.9.7/bin:$PATH" pip install -r requirements.txt
  220. ## `pyenv root`
  221. Displays the root directory where versions and shims are kept.
  222. $ pyenv root
  223. /home/user/.pyenv
  224. ## `pyenv prefix`
  225. Displays the directories where the given Python versions are installed,
  226. separated by colons. If no version is given, `pyenv prefix` displays the
  227. locations of the currently selected versions.
  228. $ pyenv prefix 3.9.7
  229. /home/user/.pyenv/versions/3.9.7
  230. ## `pyenv hooks`
  231. Lists installed hook scripts for a given pyenv command.
  232. Usage: pyenv hooks <command>
  233. ## `pyenv shims`
  234. List existing pyenv shims.
  235. Usage: pyenv shims [--short]
  236. $ pyenv shims
  237. /home/user/.pyenv/shims/2to3
  238. /home/user/.pyenv/shims/2to3-3.9
  239. /home/user/.pyenv/shims/idle
  240. /home/user/.pyenv/shims/idle3
  241. /home/user/.pyenv/shims/idle3.9
  242. /home/user/.pyenv/shims/pip
  243. /home/user/.pyenv/shims/pip3
  244. /home/user/.pyenv/shims/pip3.9
  245. /home/user/.pyenv/shims/pydoc
  246. /home/user/.pyenv/shims/pydoc3
  247. /home/user/.pyenv/shims/pydoc3.9
  248. /home/user/.pyenv/shims/python
  249. /home/user/.pyenv/shims/python3
  250. /home/user/.pyenv/shims/python3.9
  251. /home/user/.pyenv/shims/python3.9-config
  252. /home/user/.pyenv/shims/python3.9-gdb.py
  253. /home/user/.pyenv/shims/python3-config
  254. /home/user/.pyenv/shims/python-config
  255. ## `pyenv init`
  256. Configure the shell environment for pyenv
  257. Usage: eval "$(pyenv init [-|--path] [--no-rehash] [<shell>])"
  258. - Initialize shims directory, print PYENV_SHELL variable, completions path
  259. and shell function
  260. --path Print shims path
  261. --no-rehash Add no rehash command to output
  262. ## `pyenv completions`
  263. Lists available completions for a given pyenv command.
  264. Usage: pyenv completions <command> [arg1 arg2...]