| OLD | NEW |
| (Empty) |
| 1 Reference Guide | |
| 2 =============== | |
| 3 | |
| 4 ``virtualenv`` Command | |
| 5 ---------------------- | |
| 6 | |
| 7 .. _usage: | |
| 8 | |
| 9 Usage | |
| 10 ~~~~~ | |
| 11 | |
| 12 :command:`virtualenv [OPTIONS] ENV_DIR` | |
| 13 | |
| 14 Where ``ENV_DIR`` is an absolute or relative path to a directory to create | |
| 15 the virtual environment in. | |
| 16 | |
| 17 .. _options: | |
| 18 | |
| 19 Options | |
| 20 ~~~~~~~ | |
| 21 | |
| 22 .. program: virtualenv | |
| 23 | |
| 24 .. option:: --version | |
| 25 | |
| 26 show program's version number and exit | |
| 27 | |
| 28 .. option:: -h, --help | |
| 29 | |
| 30 show this help message and exit | |
| 31 | |
| 32 .. option:: -v, --verbose | |
| 33 | |
| 34 Increase verbosity. | |
| 35 | |
| 36 .. option:: -q, --quiet | |
| 37 | |
| 38 Decrease verbosity. | |
| 39 | |
| 40 .. option:: -p PYTHON_EXE, --python=PYTHON_EXE | |
| 41 | |
| 42 The Python interpreter to use, e.g., | |
| 43 --python=python2.5 will use the python2.5 interpreter | |
| 44 to create the new environment. The default is the | |
| 45 interpreter that virtualenv was installed with | |
| 46 (like ``/usr/bin/python``) | |
| 47 | |
| 48 .. option:: --clear | |
| 49 | |
| 50 Clear out the non-root install and start from scratch. | |
| 51 | |
| 52 .. option:: --system-site-packages | |
| 53 | |
| 54 Give the virtual environment access to the global | |
| 55 site-packages. | |
| 56 | |
| 57 .. option:: --always-copy | |
| 58 | |
| 59 Always copy files rather than symlinking. | |
| 60 | |
| 61 .. option:: --relocatable | |
| 62 | |
| 63 Make an EXISTING virtualenv environment relocatable. | |
| 64 This fixes up scripts and makes all .pth files relative. | |
| 65 | |
| 66 .. option:: --unzip-setuptools | |
| 67 | |
| 68 Unzip Setuptools when installing it. | |
| 69 | |
| 70 .. option:: --no-setuptools | |
| 71 | |
| 72 Do not install setuptools (or pip) in the new | |
| 73 virtualenv. | |
| 74 | |
| 75 .. option:: --no-pip | |
| 76 | |
| 77 Do not install pip in the new virtualenv. | |
| 78 | |
| 79 .. option:: --extra-search-dir=DIR | |
| 80 | |
| 81 Directory to look for setuptools/pip distributions in. | |
| 82 This option can be specified multiple times. | |
| 83 | |
| 84 .. option:: --prompt=PROMPT | |
| 85 | |
| 86 Provides an alternative prompt prefix for this | |
| 87 environment. | |
| 88 | |
| 89 .. option:: --never-download | |
| 90 | |
| 91 DEPRECATED. Retained only for backward compatibility. | |
| 92 This option has no effect. Virtualenv never downloads | |
| 93 pip or setuptools. | |
| 94 | |
| 95 .. option:: --no-site-packages | |
| 96 | |
| 97 DEPRECATED. Retained only for backward compatibility. | |
| 98 Not having access to global site-packages is now the | |
| 99 default behavior. | |
| 100 | |
| 101 .. option:: --distribute | |
| 102 .. option:: --setuptools | |
| 103 | |
| 104 Legacy; now have no effect. Before version 1.10 these could be used | |
| 105 to choose whether to install Distribute_ or Setuptools_ into the created | |
| 106 virtualenv. Distribute has now been merged into Setuptools, and the | |
| 107 latter is always installed. | |
| 108 | |
| 109 .. _Distribute: https://pypi.python.org/pypi/distribute | |
| 110 .. _Setuptools: https://pypi.python.org/pypi/setuptools | |
| 111 | |
| 112 | |
| 113 Configuration | |
| 114 ------------- | |
| 115 | |
| 116 Environment Variables | |
| 117 ~~~~~~~~~~~~~~~~~~~~~ | |
| 118 | |
| 119 Each command line option is automatically used to look for environment | |
| 120 variables with the name format ``VIRTUALENV_<UPPER_NAME>``. That means | |
| 121 the name of the command line options are capitalized and have dashes | |
| 122 (``'-'``) replaced with underscores (``'_'``). | |
| 123 | |
| 124 For example, to automatically use a custom Python binary instead of the | |
| 125 one virtualenv is run with you can also set an environment variable:: | |
| 126 | |
| 127 $ export VIRTUALENV_PYTHON=/opt/python-3.3/bin/python | |
| 128 $ virtualenv ENV | |
| 129 | |
| 130 It's the same as passing the option to virtualenv directly:: | |
| 131 | |
| 132 $ virtualenv --python=/opt/python-3.3/bin/python ENV | |
| 133 | |
| 134 This also works for appending command line options, like ``--find-links``. | |
| 135 Just leave an empty space between the passed values, e.g.:: | |
| 136 | |
| 137 $ export VIRTUALENV_EXTRA_SEARCH_DIR="/path/to/dists /path/to/other/dists" | |
| 138 $ virtualenv ENV | |
| 139 | |
| 140 is the same as calling:: | |
| 141 | |
| 142 $ virtualenv --extra-search-dir=/path/to/dists --extra-search-dir=/path/to/oth
er/dists ENV | |
| 143 | |
| 144 .. envvar:: VIRTUAL_ENV_DISABLE_PROMPT | |
| 145 | |
| 146 Any virtualenv created when this is set to a non-empty value will not have | |
| 147 it's :ref:`activate` modify the shell prompt. | |
| 148 | |
| 149 | |
| 150 Configuration File | |
| 151 ~~~~~~~~~~~~~~~~~~ | |
| 152 | |
| 153 virtualenv also looks for a standard ini config file. On Unix and Mac OS X | |
| 154 that's ``$HOME/.virtualenv/virtualenv.ini`` and on Windows, it's | |
| 155 ``%APPDATA%\virtualenv\virtualenv.ini``. | |
| 156 | |
| 157 The names of the settings are derived from the long command line option, | |
| 158 e.g. the option :option:`--python <-p>` would look like this:: | |
| 159 | |
| 160 [virtualenv] | |
| 161 python = /opt/python-3.3/bin/python | |
| 162 | |
| 163 Appending options like :option:`--extra-search-dir` can be written on multiple | |
| 164 lines:: | |
| 165 | |
| 166 [virtualenv] | |
| 167 extra-search-dir = | |
| 168 /path/to/dists | |
| 169 /path/to/other/dists | |
| 170 | |
| 171 Please have a look at the output of :option:`--help <-h>` for a full list | |
| 172 of supported options. | |
| 173 | |
| 174 | |
| 175 Extending Virtualenv | |
| 176 -------------------- | |
| 177 | |
| 178 | |
| 179 Creating Your Own Bootstrap Scripts | |
| 180 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
| 181 | |
| 182 While this creates an environment, it doesn't put anything into the | |
| 183 environment. Developers may find it useful to distribute a script | |
| 184 that sets up a particular environment, for example a script that | |
| 185 installs a particular web application. | |
| 186 | |
| 187 To create a script like this, call | |
| 188 :py:func:`virtualenv.create_bootstrap_script`, and write the | |
| 189 result to your new bootstrapping script. | |
| 190 | |
| 191 .. py:function:: create_bootstrap_script(extra_text) | |
| 192 | |
| 193 Creates a bootstrap script from ``extra_text``, which is like | |
| 194 this script but with extend_parser, adjust_options, and after_install hooks. | |
| 195 | |
| 196 This returns a string that (written to disk of course) can be used | |
| 197 as a bootstrap script with your own customizations. The script | |
| 198 will be the standard virtualenv.py script, with your extra text | |
| 199 added (your extra text should be Python code). | |
| 200 | |
| 201 If you include these functions, they will be called: | |
| 202 | |
| 203 .. py:function:: extend_parser(optparse_parser) | |
| 204 | |
| 205 You can add or remove options from the parser here. | |
| 206 | |
| 207 .. py:function:: adjust_options(options, args) | |
| 208 | |
| 209 You can change options here, or change the args (if you accept | |
| 210 different kinds of arguments, be sure you modify ``args`` so it is | |
| 211 only ``[DEST_DIR]``). | |
| 212 | |
| 213 .. py:function:: after_install(options, home_dir) | |
| 214 | |
| 215 After everything is installed, this function is called. This | |
| 216 is probably the function you are most likely to use. An | |
| 217 example would be:: | |
| 218 | |
| 219 def after_install(options, home_dir): | |
| 220 if sys.platform == 'win32': | |
| 221 bin = 'Scripts' | |
| 222 else: | |
| 223 bin = 'bin' | |
| 224 subprocess.call([join(home_dir, bin, 'easy_install'), | |
| 225 'MyPackage']) | |
| 226 subprocess.call([join(home_dir, bin, 'my-package-script'), | |
| 227 'setup', home_dir]) | |
| 228 | |
| 229 This example immediately installs a package, and runs a setup | |
| 230 script from that package. | |
| 231 | |
| 232 Bootstrap Example | |
| 233 ~~~~~~~~~~~~~~~~~ | |
| 234 | |
| 235 Here's a more concrete example of how you could use this:: | |
| 236 | |
| 237 import virtualenv, textwrap | |
| 238 output = virtualenv.create_bootstrap_script(textwrap.dedent(""" | |
| 239 import os, subprocess | |
| 240 def after_install(options, home_dir): | |
| 241 etc = join(home_dir, 'etc') | |
| 242 if not os.path.exists(etc): | |
| 243 os.makedirs(etc) | |
| 244 subprocess.call([join(home_dir, 'bin', 'easy_install'), | |
| 245 'BlogApplication']) | |
| 246 subprocess.call([join(home_dir, 'bin', 'paster'), | |
| 247 'make-config', 'BlogApplication', | |
| 248 join(etc, 'blog.ini')]) | |
| 249 subprocess.call([join(home_dir, 'bin', 'paster'), | |
| 250 'setup-app', join(etc, 'blog.ini')]) | |
| 251 """)) | |
| 252 f = open('blog-bootstrap.py', 'w').write(output) | |
| 253 | |
| 254 Another example is available `here`__. | |
| 255 | |
| 256 .. __: https://github.com/socialplanning/fassembler/blob/master/fassembler/creat
e-venv-script.py | |
| OLD | NEW |