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.

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