選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

254 行
8.4 KiB

9年前
  1. # pyenv-virtualenv
  2. [![Join the chat at https://gitter.im/yyuu/pyenv-virtualenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/yyuu/pyenv-virtualenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  3. [![Build Status](https://travis-ci.org/yyuu/pyenv-virtualenv.svg?branch=master)](https://travis-ci.org/yyuu/pyenv-virtualenv)
  4. pyenv-virtualenv is a [pyenv](https://github.com/yyuu/pyenv) plugin
  5. that provides features to manage virtualenvs and conda environments
  6. for Python on UNIX-like systems.
  7. (NOTICE: If you are an existing user of [virtualenvwrapper](http://pypi.python.org/pypi/virtualenvwrapper)
  8. and you love it, [pyenv-virtualenvwrapper](https://github.com/yyuu/pyenv-virtualenvwrapper) may help you
  9. (additionally) to manage your virtualenvs.)
  10. ## Installation
  11. ### Installing as a pyenv plugin
  12. This will install the latest development version of pyenv-virtualenv into
  13. the `~/.pyenv/plugins/pyenv-virtualenv` directory.
  14. **Important note:** If you installed pyenv into a non-standard directory, make
  15. sure that you clone this repo into the 'plugins' directory of wherever you
  16. installed into.
  17. From inside that directory you can:
  18. - Check out a specific release tag.
  19. - Get the latest development release by running `git pull` to download the
  20. latest changes.
  21. 1. **Check out pyenv-virtualenv into plugin directory**
  22. ```
  23. $ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
  24. ```
  25. 2. (OPTIONAL) **Add `pyenv virtualenv-init` to your shell** to enable auto-activation of virtualenv. This is entirely optional but pretty useful.
  26. ```
  27. $ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
  28. ```
  29. **Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
  30. **Pyenv note**: You may also need to add `eval "$(pyenv init -)"` to your profile if you haven't done so already.
  31. 3. **Restart your shell to enable pyenv-virtualenv**
  32. ```
  33. $ exec "$SHELL"
  34. ```
  35. ### Installing with Homebrew (for OS X users)
  36. Mac OS X users can install pyenv-virtualenv with the
  37. [Homebrew](http://brew.sh) package manager.
  38. This will give you access to the `pyenv-virtualenv` command. If you have pyenv
  39. installed, you will also be able to use the `pyenv virtualenv` command.
  40. *This is the recommended method of installation if you installed pyenv
  41. with Homebrew.*
  42. ```
  43. $ brew install pyenv-virtualenv
  44. ```
  45. Or, if you would like to install the latest development release:
  46. ```
  47. $ brew install --HEAD pyenv-virtualenv
  48. ```
  49. After installation, you'll still need to add
  50. ```
  51. eval "$(pyenv init -)"
  52. eval "$(pyenv virtualenv-init -)"
  53. ```
  54. to your profile (as stated in the caveats). You'll only ever have to do this once.
  55. ## Usage
  56. ### Using `pyenv virtualenv` with pyenv
  57. To create a virtualenv for the Python version used with pyenv, run
  58. `pyenv virtualenv`, specifying the Python version you want and the name
  59. of the virtualenv directory. For example,
  60. ```
  61. $ pyenv virtualenv 2.7.10 my-virtual-env-2.7.10
  62. ```
  63. will create a virtualenv based on Python 2.7.10 under `~/.pyenv/versions` in a
  64. folder called `my-virtual-env-2.7.10`.
  65. ### Create virtualenv from current version
  66. If there is only one argument given to `pyenv virtualenv`, the virtualenv will
  67. be created with the given name based on the current pyenv Python version.
  68. ```
  69. $ pyenv version
  70. 3.4.3 (set by /home/yyuu/.pyenv/version)
  71. $ pyenv virtualenv venv34
  72. ```
  73. ### List existing virtualenvs
  74. `pyenv virtualenvs` shows you the list of existing virtualenvs and `conda` environments.
  75. ```
  76. $ pyenv shell venv27
  77. $ pyenv virtualenvs
  78. miniconda3-3.9.1 (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
  79. miniconda3-3.9.1/envs/myenv (created from /home/yyuu/.pyenv/versions/miniconda3-3.9.1)
  80. * venv27 (created from /home/yyuu/.pyenv/versions/2.7.10)
  81. venv34 (created from /home/yyuu/.pyenv/versions/3.4.3)
  82. ```
  83. ### Activate virtualenv
  84. Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might
  85. require you to `activate` the virtualenv and `conda` environments.
  86. `pyenv-virtualenv` will automatically activate/deactivate the virtualenv if
  87. the `eval "$(pyenv virtualenv-init -)"` is properly configured in your shell.
  88. You can also activate and deactivate a pyenv virtualenv manually:
  89. ```sh
  90. pyenv activate <name>
  91. pyenv deactivate
  92. ```
  93. ### Delete existing virtualenv
  94. Removing the directory in `~/.pyenv/versions` will delete the virtualenv, or you can run:
  95. ```sh
  96. pyenv uninstall my-virtual-env
  97. ```
  98. ### virtualenv and pyvenv
  99. There is a [venv](http://docs.python.org/3/library/venv.html) module available
  100. for CPython 3.3 and newer.
  101. It provides a command-line tool `pyvenv` which is the successor of `virtualenv`
  102. and distributed by default.
  103. `pyenv-virtualenv` uses `pyvenv` if it is available and the `virtualenv`
  104. command is not available.
  105. ### Anaconda and Miniconda
  106. Because Anaconda and Miniconda may install standard commands (e.g. `curl`, `openssl`, `sqlite3`, etc.) into their prefix,
  107. we'd recommend you to install [pyenv-which-ext](https://github.com/yyuu/pyenv-which-ext).
  108. You can manage `conda` environments by `conda create` as same manner as standard Anaconda/Miniconda installations.
  109. To use those environments, you can use `pyenv activate` and `pyenv deactivate`.
  110. ```
  111. $ pyenv version
  112. miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
  113. $ conda env list
  114. # conda environments:
  115. #
  116. myenv /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv
  117. root * /home/yyuu/.pyenv/versions/miniconda3-3.9.1
  118. $ pyenv activate miniconda3-3.9.1/envs/myenv
  119. discarding /home/yyuu/.pyenv/versions/miniconda3-3.9.1/bin from PATH
  120. prepending /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin to PATH
  121. $ python --version
  122. Python 3.4.3 :: Continuum Analytics, Inc.
  123. $ pyenv deactivate
  124. discarding /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin from PATH
  125. ```
  126. If `conda` is available, `pyenv virtualenv` will use it to create environment by `conda create`.
  127. ```
  128. $ pyenv version
  129. miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
  130. $ pyenv virtualenv myenv2
  131. $ conda env list
  132. # conda environments:
  133. #
  134. myenv /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv
  135. myenv /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv2
  136. root * /home/yyuu/.pyenv/versions/miniconda3-3.9.1
  137. ```
  138. You can use version like `miniconda3-3.9.1/envs/myenv` to specify `conda` environment as a version in pyenv.
  139. ```
  140. $ pyenv version
  141. miniconda3-3.9.1 (set by /home/yyuu/.pyenv/version)
  142. $ pyenv shell miniconda3-3.9.1/envs/myenv
  143. $ which python
  144. /home/yyuu/.pyenv/versions/miniconda3-3.9.1/envs/myenv/bin/python
  145. ```
  146. ### Special environment variables
  147. You can set certain environment variables to control pyenv-virtualenv.
  148. * `PYENV_VIRTUALENV_CACHE_PATH`, if set, specifies a directory to use for
  149. caching downloaded package files.
  150. * `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to install the desired
  151. version of virtualenv. If `virtualenv` has not been installed,
  152. pyenv-virtualenv will try to install the given version of virtualenv.
  153. * `GET_PIP`, if set and `pyvenv` is preferred over `virtualenv`,
  154. use `get_pip.py` from the specified location.
  155. * `GET_PIP_URL`, if set and `pyvenv` is preferred over
  156. `virtualenv`, download `get_pip.py` from the specified URL.
  157. * `PIP_VERSION`, if set and `pyvenv` is preferred
  158. over `virtualenv`, install the specified version of pip.
  159. ## Version History
  160. See [CHANGELOG.md](CHANGELOG.md).
  161. ### License
  162. (The MIT License)
  163. * Copyright (c) 2015 Yamashita, Yuu
  164. Permission is hereby granted, free of charge, to any person obtaining
  165. a copy of this software and associated documentation files (the
  166. "Software"), to deal in the Software without restriction, including
  167. without limitation the rights to use, copy, modify, merge, publish,
  168. distribute, sublicense, and/or sell copies of the Software, and to
  169. permit persons to whom the Software is furnished to do so, subject to
  170. the following conditions:
  171. The above copyright notice and this permission notice shall be
  172. included in all copies or substantial portions of the Software.
  173. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  174. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  175. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  176. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  177. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  178. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  179. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.