python/virtualenv/docs/virtualenv.rst

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1
michael@0 2 Introduction
michael@0 3 ------------
michael@0 4
michael@0 5 ``virtualenv`` is a tool to create isolated Python environments.
michael@0 6
michael@0 7 The basic problem being addressed is one of dependencies and versions,
michael@0 8 and indirectly permissions. Imagine you have an application that
michael@0 9 needs version 1 of LibFoo, but another application requires version
michael@0 10 2. How can you use both these applications? If you install
michael@0 11 everything into ``/usr/lib/python2.7/site-packages`` (or whatever your
michael@0 12 platform's standard location is), it's easy to end up in a situation
michael@0 13 where you unintentionally upgrade an application that shouldn't be
michael@0 14 upgraded.
michael@0 15
michael@0 16 Or more generally, what if you want to install an application *and
michael@0 17 leave it be*? If an application works, any change in its libraries or
michael@0 18 the versions of those libraries can break the application.
michael@0 19
michael@0 20 Also, what if you can't install packages into the global
michael@0 21 ``site-packages`` directory? For instance, on a shared host.
michael@0 22
michael@0 23 In all these cases, ``virtualenv`` can help you. It creates an
michael@0 24 environment that has its own installation directories, that doesn't
michael@0 25 share libraries with other virtualenv environments (and optionally
michael@0 26 doesn't access the globally installed libraries either).
michael@0 27
michael@0 28
michael@0 29 Installation
michael@0 30 ------------
michael@0 31
michael@0 32 .. warning::
michael@0 33
michael@0 34 We advise installing virtualenv-1.9 or greater. Prior to version 1.9, the
michael@0 35 pip included in virtualenv did not not download from PyPI over SSL.
michael@0 36
michael@0 37 .. warning::
michael@0 38
michael@0 39 When using pip to install virtualenv, we advise using pip 1.3 or greater.
michael@0 40 Prior to version 1.3, pip did not not download from PyPI over SSL.
michael@0 41
michael@0 42 .. warning::
michael@0 43
michael@0 44 We advise against using easy_install to install virtualenv when using
michael@0 45 setuptools < 0.9.7, because easy_install didn't download from PyPI over SSL
michael@0 46 and was broken in some subtle ways.
michael@0 47
michael@0 48 To install globally with `pip` (if you have pip 1.3 or greater installed globally):
michael@0 49
michael@0 50 ::
michael@0 51
michael@0 52 $ [sudo] pip install virtualenv
michael@0 53
michael@0 54 Or to get the latest unreleased dev version:
michael@0 55
michael@0 56 ::
michael@0 57
michael@0 58 $ [sudo] pip install https://github.com/pypa/virtualenv/tarball/develop
michael@0 59
michael@0 60
michael@0 61 To install globally from source:
michael@0 62
michael@0 63 ::
michael@0 64
michael@0 65 $ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
michael@0 66 $ tar xvfz virtualenv-X.X.tar.gz
michael@0 67 $ cd virtualenv-X.X
michael@0 68 $ [sudo] python setup.py install
michael@0 69
michael@0 70
michael@0 71 To *use* locally from source:
michael@0 72
michael@0 73 ::
michael@0 74
michael@0 75 $ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
michael@0 76 $ tar xvfz virtualenv-X.X.tar.gz
michael@0 77 $ cd virtualenv-X.X
michael@0 78 $ python virtualenv.py myVE
michael@0 79
michael@0 80 .. note::
michael@0 81
michael@0 82 The ``virtualenv.py`` script is *not* supported if run without the
michael@0 83 necessary pip/setuptools/virtualenv distributions available locally. All
michael@0 84 of the installation methods above include a ``virtualenv_support``
michael@0 85 directory alongside ``virtualenv.py`` which contains a complete set of
michael@0 86 pip and setuptools distributions, and so are fully supported.
michael@0 87
michael@0 88 Usage
michael@0 89 -----
michael@0 90
michael@0 91 The basic usage is::
michael@0 92
michael@0 93 $ virtualenv ENV
michael@0 94
michael@0 95 This creates ``ENV/lib/pythonX.X/site-packages``, where any libraries you
michael@0 96 install will go. It also creates ``ENV/bin/python``, which is a Python
michael@0 97 interpreter that uses this environment. Anytime you use that interpreter
michael@0 98 (including when a script has ``#!/path/to/ENV/bin/python`` in it) the libraries
michael@0 99 in that environment will be used.
michael@0 100
michael@0 101 It also installs `Setuptools
michael@0 102 <http://peak.telecommunity.com/DevCenter/setuptools>`_ into the environment.
michael@0 103
michael@0 104 .. note::
michael@0 105
michael@0 106 Virtualenv (<1.10) used to provide a ``--distribute`` option to use the
michael@0 107 setuptools fork Distribute_. Since Distribute has been merged back into
michael@0 108 setuptools this option is now no-op, it will always use the improved
michael@0 109 setuptools releases.
michael@0 110
michael@0 111 A new virtualenv also includes the `pip <http://pypi.python.org/pypi/pip>`_
michael@0 112 installer, so you can use ``ENV/bin/pip`` to install additional packages into
michael@0 113 the environment.
michael@0 114
michael@0 115 .. _Distribute: https://pypi.python.org/pypi/distribute
michael@0 116
michael@0 117 activate script
michael@0 118 ~~~~~~~~~~~~~~~
michael@0 119
michael@0 120 In a newly created virtualenv there will be a ``bin/activate`` shell
michael@0 121 script. For Windows systems, activation scripts are provided for CMD.exe
michael@0 122 and Powershell.
michael@0 123
michael@0 124 On Posix systems you can do::
michael@0 125
michael@0 126 $ source bin/activate
michael@0 127
michael@0 128 This will change your ``$PATH`` so its first entry is the virtualenv's
michael@0 129 ``bin/`` directory. (You have to use ``source`` because it changes your
michael@0 130 shell environment in-place.) This is all it does; it's purely a
michael@0 131 convenience. If you directly run a script or the python interpreter
michael@0 132 from the virtualenv's ``bin/`` directory (e.g. ``path/to/env/bin/pip``
michael@0 133 or ``/path/to/env/bin/python script.py``) there's no need for
michael@0 134 activation.
michael@0 135
michael@0 136 After activating an environment you can use the function ``deactivate`` to
michael@0 137 undo the changes to your ``$PATH``.
michael@0 138
michael@0 139 The ``activate`` script will also modify your shell prompt to indicate
michael@0 140 which environment is currently active. You can disable this behavior,
michael@0 141 which can be useful if you have your own custom prompt that already
michael@0 142 displays the active environment name. To do so, set the
michael@0 143 ``VIRTUAL_ENV_DISABLE_PROMPT`` environment variable to any non-empty
michael@0 144 value before running the ``activate`` script.
michael@0 145
michael@0 146 On Windows you just do::
michael@0 147
michael@0 148 > \path\to\env\Scripts\activate
michael@0 149
michael@0 150 And type `deactivate` to undo the changes.
michael@0 151
michael@0 152 Based on your active shell (CMD.exe or Powershell.exe), Windows will use
michael@0 153 either activate.bat or activate.ps1 (as appropriate) to activate the
michael@0 154 virtual environment. If using Powershell, see the notes about code signing
michael@0 155 below.
michael@0 156
michael@0 157 .. note::
michael@0 158
michael@0 159 If using Powershell, the ``activate`` script is subject to the
michael@0 160 `execution policies`_ on the system. By default on Windows 7, the system's
michael@0 161 excution policy is set to ``Restricted``, meaning no scripts like the
michael@0 162 ``activate`` script are allowed to be executed. But that can't stop us
michael@0 163 from changing that slightly to allow it to be executed.
michael@0 164
michael@0 165 In order to use the script, you have to relax your system's execution
michael@0 166 policy to ``AllSigned``, meaning all scripts on the system must be
michael@0 167 digitally signed to be executed. Since the virtualenv activation
michael@0 168 script is signed by one of the authors (Jannis Leidel) this level of
michael@0 169 the execution policy suffices. As an administrator run::
michael@0 170
michael@0 171 PS C:\> Set-ExecutionPolicy AllSigned
michael@0 172
michael@0 173 Then you'll be asked to trust the signer, when executing the script.
michael@0 174 You will be prompted with the following::
michael@0 175
michael@0 176 PS C:\> virtualenv .\foo
michael@0 177 New python executable in C:\foo\Scripts\python.exe
michael@0 178 Installing setuptools................done.
michael@0 179 Installing pip...................done.
michael@0 180 PS C:\> .\foo\scripts\activate
michael@0 181
michael@0 182 Do you want to run software from this untrusted publisher?
michael@0 183 File C:\foo\scripts\activate.ps1 is published by E=jannis@leidel.info,
michael@0 184 CN=Jannis Leidel, L=Berlin, S=Berlin, C=DE, Description=581796-Gh7xfJxkxQSIO4E0
michael@0 185 and is not trusted on your system. Only run scripts from trusted publishers.
michael@0 186 [V] Never run [D] Do not run [R] Run once [A] Always run [?] Help
michael@0 187 (default is "D"):A
michael@0 188 (foo) PS C:\>
michael@0 189
michael@0 190 If you select ``[A] Always Run``, the certificate will be added to the
michael@0 191 Trusted Publishers of your user account, and will be trusted in this
michael@0 192 user's context henceforth. If you select ``[R] Run Once``, the script will
michael@0 193 be run, but you will be prometed on a subsequent invocation. Advanced users
michael@0 194 can add the signer's certificate to the Trusted Publishers of the Computer
michael@0 195 account to apply to all users (though this technique is out of scope of this
michael@0 196 document).
michael@0 197
michael@0 198 Alternatively, you may relax the system execution policy to allow running
michael@0 199 of local scripts without verifying the code signature using the following::
michael@0 200
michael@0 201 PS C:\> Set-ExecutionPolicy RemoteSigned
michael@0 202
michael@0 203 Since the ``activate.ps1`` script is generated locally for each virtualenv,
michael@0 204 it is not considered a remote script and can then be executed.
michael@0 205
michael@0 206 .. _`execution policies`: http://technet.microsoft.com/en-us/library/dd347641.aspx
michael@0 207
michael@0 208 The ``--system-site-packages`` Option
michael@0 209 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
michael@0 210
michael@0 211 If you build with ``virtualenv --system-site-packages ENV``, your virtual
michael@0 212 environment will inherit packages from ``/usr/lib/python2.7/site-packages``
michael@0 213 (or wherever your global site-packages directory is).
michael@0 214
michael@0 215 This can be used if you have control over the global site-packages directory,
michael@0 216 and you want to depend on the packages there. If you want isolation from the
michael@0 217 global system, do not use this flag.
michael@0 218
michael@0 219
michael@0 220 Environment variables and configuration files
michael@0 221 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
michael@0 222
michael@0 223 virtualenv can not only be configured by passing command line options such as
michael@0 224 ``--python`` but also by two other means:
michael@0 225
michael@0 226 - Environment variables
michael@0 227
michael@0 228 Each command line option is automatically used to look for environment
michael@0 229 variables with the name format ``VIRTUALENV_<UPPER_NAME>``. That means
michael@0 230 the name of the command line options are capitalized and have dashes
michael@0 231 (``'-'``) replaced with underscores (``'_'``).
michael@0 232
michael@0 233 For example, to automatically use a custom Python binary instead of the
michael@0 234 one virtualenv is run with you can also set an environment variable::
michael@0 235
michael@0 236 $ export VIRTUALENV_PYTHON=/opt/python-3.3/bin/python
michael@0 237 $ virtualenv ENV
michael@0 238
michael@0 239 It's the same as passing the option to virtualenv directly::
michael@0 240
michael@0 241 $ virtualenv --python=/opt/python-3.3/bin/python ENV
michael@0 242
michael@0 243 This also works for appending command line options, like ``--find-links``.
michael@0 244 Just leave an empty space between the passsed values, e.g.::
michael@0 245
michael@0 246 $ export VIRTUALENV_EXTRA_SEARCH_DIR="/path/to/dists /path/to/other/dists"
michael@0 247 $ virtualenv ENV
michael@0 248
michael@0 249 is the same as calling::
michael@0 250
michael@0 251 $ virtualenv --extra-search-dir=/path/to/dists --extra-search-dir=/path/to/other/dists ENV
michael@0 252
michael@0 253 - Config files
michael@0 254
michael@0 255 virtualenv also looks for a standard ini config file. On Unix and Mac OS X
michael@0 256 that's ``$HOME/.virtualenv/virtualenv.ini`` and on Windows, it's
michael@0 257 ``%APPDATA%\virtualenv\virtualenv.ini``.
michael@0 258
michael@0 259 The names of the settings are derived from the long command line option,
michael@0 260 e.g. the option ``--python`` would look like this::
michael@0 261
michael@0 262 [virtualenv]
michael@0 263 python = /opt/python-3.3/bin/python
michael@0 264
michael@0 265 Appending options like ``--extra-search-dir`` can be written on multiple
michael@0 266 lines::
michael@0 267
michael@0 268 [virtualenv]
michael@0 269 extra-search-dir =
michael@0 270 /path/to/dists
michael@0 271 /path/to/other/dists
michael@0 272
michael@0 273 Please have a look at the output of ``virtualenv --help`` for a full list
michael@0 274 of supported options.
michael@0 275
michael@0 276 Windows Notes
michael@0 277 ~~~~~~~~~~~~~
michael@0 278
michael@0 279 Some paths within the virtualenv are slightly different on Windows: scripts and
michael@0 280 executables on Windows go in ``ENV\Scripts\`` instead of ``ENV/bin/`` and
michael@0 281 libraries go in ``ENV\Lib\`` rather than ``ENV/lib/``.
michael@0 282
michael@0 283 To create a virtualenv under a path with spaces in it on Windows, you'll need
michael@0 284 the `win32api <http://sourceforge.net/projects/pywin32/>`_ library installed.
michael@0 285
michael@0 286 PyPy Support
michael@0 287 ~~~~~~~~~~~~
michael@0 288
michael@0 289 Beginning with virtualenv version 1.5 `PyPy <http://pypy.org>`_ is
michael@0 290 supported. To use PyPy 1.4 or 1.4.1, you need a version of virtualenv >= 1.5.
michael@0 291 To use PyPy 1.5, you need a version of virtualenv >= 1.6.1.
michael@0 292
michael@0 293 Creating Your Own Bootstrap Scripts
michael@0 294 -----------------------------------
michael@0 295
michael@0 296 While this creates an environment, it doesn't put anything into the
michael@0 297 environment. Developers may find it useful to distribute a script
michael@0 298 that sets up a particular environment, for example a script that
michael@0 299 installs a particular web application.
michael@0 300
michael@0 301 To create a script like this, call
michael@0 302 ``virtualenv.create_bootstrap_script(extra_text)``, and write the
michael@0 303 result to your new bootstrapping script. Here's the documentation
michael@0 304 from the docstring:
michael@0 305
michael@0 306 Creates a bootstrap script, which is like this script but with
michael@0 307 extend_parser, adjust_options, and after_install hooks.
michael@0 308
michael@0 309 This returns a string that (written to disk of course) can be used
michael@0 310 as a bootstrap script with your own customizations. The script
michael@0 311 will be the standard virtualenv.py script, with your extra text
michael@0 312 added (your extra text should be Python code).
michael@0 313
michael@0 314 If you include these functions, they will be called:
michael@0 315
michael@0 316 ``extend_parser(optparse_parser)``:
michael@0 317 You can add or remove options from the parser here.
michael@0 318
michael@0 319 ``adjust_options(options, args)``:
michael@0 320 You can change options here, or change the args (if you accept
michael@0 321 different kinds of arguments, be sure you modify ``args`` so it is
michael@0 322 only ``[DEST_DIR]``).
michael@0 323
michael@0 324 ``after_install(options, home_dir)``:
michael@0 325
michael@0 326 After everything is installed, this function is called. This
michael@0 327 is probably the function you are most likely to use. An
michael@0 328 example would be::
michael@0 329
michael@0 330 def after_install(options, home_dir):
michael@0 331 if sys.platform == 'win32':
michael@0 332 bin = 'Scripts'
michael@0 333 else:
michael@0 334 bin = 'bin'
michael@0 335 subprocess.call([join(home_dir, bin, 'easy_install'),
michael@0 336 'MyPackage'])
michael@0 337 subprocess.call([join(home_dir, bin, 'my-package-script'),
michael@0 338 'setup', home_dir])
michael@0 339
michael@0 340 This example immediately installs a package, and runs a setup
michael@0 341 script from that package.
michael@0 342
michael@0 343 Bootstrap Example
michael@0 344 ~~~~~~~~~~~~~~~~~
michael@0 345
michael@0 346 Here's a more concrete example of how you could use this::
michael@0 347
michael@0 348 import virtualenv, textwrap
michael@0 349 output = virtualenv.create_bootstrap_script(textwrap.dedent("""
michael@0 350 import os, subprocess
michael@0 351 def after_install(options, home_dir):
michael@0 352 etc = join(home_dir, 'etc')
michael@0 353 if not os.path.exists(etc):
michael@0 354 os.makedirs(etc)
michael@0 355 subprocess.call([join(home_dir, 'bin', 'easy_install'),
michael@0 356 'BlogApplication'])
michael@0 357 subprocess.call([join(home_dir, 'bin', 'paster'),
michael@0 358 'make-config', 'BlogApplication',
michael@0 359 join(etc, 'blog.ini')])
michael@0 360 subprocess.call([join(home_dir, 'bin', 'paster'),
michael@0 361 'setup-app', join(etc, 'blog.ini')])
michael@0 362 """))
michael@0 363 f = open('blog-bootstrap.py', 'w').write(output)
michael@0 364
michael@0 365 Another example is available `here
michael@0 366 <https://github.com/socialplanning/fassembler/blob/master/fassembler/create-venv-script.py>`_.
michael@0 367
michael@0 368
michael@0 369 Using Virtualenv without ``bin/python``
michael@0 370 ---------------------------------------
michael@0 371
michael@0 372 Sometimes you can't or don't want to use the Python interpreter
michael@0 373 created by the virtualenv. For instance, in a `mod_python
michael@0 374 <http://www.modpython.org/>`_ or `mod_wsgi <http://www.modwsgi.org/>`_
michael@0 375 environment, there is only one interpreter.
michael@0 376
michael@0 377 Luckily, it's easy. You must use the custom Python interpreter to
michael@0 378 *install* libraries. But to *use* libraries, you just have to be sure
michael@0 379 the path is correct. A script is available to correct the path. You
michael@0 380 can setup the environment like::
michael@0 381
michael@0 382 activate_this = '/path/to/env/bin/activate_this.py'
michael@0 383 execfile(activate_this, dict(__file__=activate_this))
michael@0 384
michael@0 385 This will change ``sys.path`` and even change ``sys.prefix``, but also allow
michael@0 386 you to use an existing interpreter. Items in your environment will show up
michael@0 387 first on ``sys.path``, before global items. However, global items will
michael@0 388 always be accessible (as if the ``--system-site-packages`` flag had been used
michael@0 389 in creating the environment, whether it was or not). Also, this cannot undo
michael@0 390 the activation of other environments, or modules that have been imported.
michael@0 391 You shouldn't try to, for instance, activate an environment before a web
michael@0 392 request; you should activate *one* environment as early as possible, and not
michael@0 393 do it again in that process.
michael@0 394
michael@0 395 Making Environments Relocatable
michael@0 396 -------------------------------
michael@0 397
michael@0 398 Note: this option is somewhat experimental, and there are probably
michael@0 399 caveats that have not yet been identified.
michael@0 400
michael@0 401 .. warning::
michael@0 402
michael@0 403 The ``--relocatable`` option currently has a number of issues,
michael@0 404 and is not guaranteed to work in all circumstances. It is possible
michael@0 405 that the option will be deprecated in a future version of ``virtualenv``.
michael@0 406
michael@0 407 Normally environments are tied to a specific path. That means that
michael@0 408 you cannot move an environment around or copy it to another computer.
michael@0 409 You can fix up an environment to make it relocatable with the
michael@0 410 command::
michael@0 411
michael@0 412 $ virtualenv --relocatable ENV
michael@0 413
michael@0 414 This will make some of the files created by setuptools use relative paths,
michael@0 415 and will change all the scripts to use ``activate_this.py`` instead of using
michael@0 416 the location of the Python interpreter to select the environment.
michael@0 417
michael@0 418 **Note:** scripts which have been made relocatable will only work if
michael@0 419 the virtualenv is activated, specifically the python executable from
michael@0 420 the virtualenv must be the first one on the system PATH. Also note that
michael@0 421 the activate scripts are not currently made relocatable by
michael@0 422 ``virtualenv --relocatable``.
michael@0 423
michael@0 424 **Note:** you must run this after you've installed *any* packages into
michael@0 425 the environment. If you make an environment relocatable, then
michael@0 426 install a new package, you must run ``virtualenv --relocatable``
michael@0 427 again.
michael@0 428
michael@0 429 Also, this **does not make your packages cross-platform**. You can
michael@0 430 move the directory around, but it can only be used on other similar
michael@0 431 computers. Some known environmental differences that can cause
michael@0 432 incompatibilities: a different version of Python, when one platform
michael@0 433 uses UCS2 for its internal unicode representation and another uses
michael@0 434 UCS4 (a compile-time option), obvious platform changes like Windows
michael@0 435 vs. Linux, or Intel vs. ARM, and if you have libraries that bind to C
michael@0 436 libraries on the system, if those C libraries are located somewhere
michael@0 437 different (either different versions, or a different filesystem
michael@0 438 layout).
michael@0 439
michael@0 440 If you use this flag to create an environment, currently, the
michael@0 441 ``--system-site-packages`` option will be implied.
michael@0 442
michael@0 443 The ``--extra-search-dir`` option
michael@0 444 ---------------------------------
michael@0 445
michael@0 446 This option allows you to provide your own versions of setuptools and/or
michael@0 447 pip to use instead of the embedded versions that come with virtualenv.
michael@0 448
michael@0 449 To use this feature, pass one or more ``--extra-search-dir`` options to
michael@0 450 virtualenv like this::
michael@0 451
michael@0 452 $ virtualenv --extra-search-dir=/path/to/distributions ENV
michael@0 453
michael@0 454 The ``/path/to/distributions`` path should point to a directory that contains
michael@0 455 setuptools and/or pip wheels.
michael@0 456
michael@0 457 virtualenv will look for wheels in the specified directories, but will use
michael@0 458 pip's standard algorithm for selecting the wheel to install, which looks for
michael@0 459 the latest compatible wheel.
michael@0 460
michael@0 461 As well as the extra directories, the search order includes:
michael@0 462
michael@0 463 #. The ``virtualenv_support`` directory relative to virtualenv.py
michael@0 464 #. The directory where virtualenv.py is located.
michael@0 465 #. The current directory.
michael@0 466
michael@0 467 If no satisfactory local distributions are found, virtualenv will
michael@0 468 fail. Virtualenv will never download packages.
michael@0 469
michael@0 470
michael@0 471 Compare & Contrast with Alternatives
michael@0 472 ------------------------------------
michael@0 473
michael@0 474 There are several alternatives that create isolated environments:
michael@0 475
michael@0 476 * ``workingenv`` (which I do not suggest you use anymore) is the
michael@0 477 predecessor to this library. It used the main Python interpreter,
michael@0 478 but relied on setting ``$PYTHONPATH`` to activate the environment.
michael@0 479 This causes problems when running Python scripts that aren't part of
michael@0 480 the environment (e.g., a globally installed ``hg`` or ``bzr``). It
michael@0 481 also conflicted a lot with Setuptools.
michael@0 482
michael@0 483 * `virtual-python
michael@0 484 <http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python>`_
michael@0 485 is also a predecessor to this library. It uses only symlinks, so it
michael@0 486 couldn't work on Windows. It also symlinks over the *entire*
michael@0 487 standard library and global ``site-packages``. As a result, it
michael@0 488 won't see new additions to the global ``site-packages``.
michael@0 489
michael@0 490 This script only symlinks a small portion of the standard library
michael@0 491 into the environment, and so on Windows it is feasible to simply
michael@0 492 copy these files over. Also, it creates a new/empty
michael@0 493 ``site-packages`` and also adds the global ``site-packages`` to the
michael@0 494 path, so updates are tracked separately. This script also installs
michael@0 495 Setuptools automatically, saving a step and avoiding the need for
michael@0 496 network access.
michael@0 497
michael@0 498 * `zc.buildout <http://pypi.python.org/pypi/zc.buildout>`_ doesn't
michael@0 499 create an isolated Python environment in the same style, but
michael@0 500 achieves similar results through a declarative config file that sets
michael@0 501 up scripts with very particular packages. As a declarative system,
michael@0 502 it is somewhat easier to repeat and manage, but more difficult to
michael@0 503 experiment with. ``zc.buildout`` includes the ability to setup
michael@0 504 non-Python systems (e.g., a database server or an Apache instance).
michael@0 505
michael@0 506 I *strongly* recommend anyone doing application development or
michael@0 507 deployment use one of these tools.
michael@0 508
michael@0 509 Contributing
michael@0 510 ------------
michael@0 511
michael@0 512 Refer to the `pip development`_ documentation - it applies equally to
michael@0 513 virtualenv, except that virtualenv issues should filed on the `virtualenv
michael@0 514 repo`_ at GitHub.
michael@0 515
michael@0 516 Virtualenv's release schedule is tied to pip's -- each time there's a new pip
michael@0 517 release, there will be a new virtualenv release that bundles the new version of
michael@0 518 pip.
michael@0 519
michael@0 520 Files in the `virtualenv_embedded/` subdirectory are embedded into
michael@0 521 `virtualenv.py` itself as base64-encoded strings (in order to support
michael@0 522 single-file use of `virtualenv.py` without installing it). If your patch
michael@0 523 changes any file in `virtualenv_embedded/`, run `bin/rebuild-script.py` to
michael@0 524 update the embedded version of that file in `virtualenv.py`; commit that and
michael@0 525 submit it as part of your patch / pull request.
michael@0 526
michael@0 527 .. _pip development: http://www.pip-installer.org/en/latest/development.html
michael@0 528 .. _virtualenv repo: https://github.com/pypa/virtualenv/
michael@0 529
michael@0 530 Running the tests
michael@0 531 ~~~~~~~~~~~~~~~~~
michael@0 532
michael@0 533 Virtualenv's test suite is small and not yet at all comprehensive, but we aim
michael@0 534 to grow it.
michael@0 535
michael@0 536 The easy way to run tests (handles test dependencies automatically)::
michael@0 537
michael@0 538 $ python setup.py test
michael@0 539
michael@0 540 If you want to run only a selection of the tests, you'll need to run them
michael@0 541 directly with nose instead. Create a virtualenv, and install required
michael@0 542 packages::
michael@0 543
michael@0 544 $ pip install nose mock
michael@0 545
michael@0 546 Run nosetests::
michael@0 547
michael@0 548 $ nosetests
michael@0 549
michael@0 550 Or select just a single test file to run::
michael@0 551
michael@0 552 $ nosetests tests.test_virtualenv
michael@0 553
michael@0 554
michael@0 555 Other Documentation and Links
michael@0 556 -----------------------------
michael@0 557
michael@0 558 * James Gardner has written a tutorial on using `virtualenv with
michael@0 559 Pylons
michael@0 560 <http://wiki.pylonshq.com/display/pylonscookbook/Using+a+Virtualenv+Sandbox>`_.
michael@0 561
michael@0 562 * `Blog announcement
michael@0 563 <http://blog.ianbicking.org/2007/10/10/workingenv-is-dead-long-live-virtualenv/>`_.
michael@0 564
michael@0 565 * Doug Hellmann wrote a description of his `command-line work flow
michael@0 566 using virtualenv (virtualenvwrapper)
michael@0 567 <http://www.doughellmann.com/articles/CompletelyDifferent-2008-05-virtualenvwrapper/index.html>`_
michael@0 568 including some handy scripts to make working with multiple
michael@0 569 environments easier. He also wrote `an example of using virtualenv
michael@0 570 to try IPython
michael@0 571 <http://www.doughellmann.com/articles/CompletelyDifferent-2008-02-ipython-and-virtualenv/index.html>`_.
michael@0 572
michael@0 573 * Chris Perkins created a `showmedo video including virtualenv
michael@0 574 <http://showmedo.com/videos/video?name=2910000&fromSeriesID=291>`_.
michael@0 575
michael@0 576 * `Using virtualenv with mod_wsgi
michael@0 577 <http://code.google.com/p/modwsgi/wiki/VirtualEnvironments>`_.
michael@0 578
michael@0 579 * `virtualenv commands
michael@0 580 <https://github.com/thisismedium/virtualenv-commands>`_ for some more
michael@0 581 workflow-related tools around virtualenv.
michael@0 582
michael@0 583 Status and License
michael@0 584 ------------------
michael@0 585
michael@0 586 ``virtualenv`` is a successor to `workingenv
michael@0 587 <http://cheeseshop.python.org/pypi/workingenv.py>`_, and an extension
michael@0 588 of `virtual-python
michael@0 589 <http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python>`_.
michael@0 590
michael@0 591 It was written by Ian Bicking, sponsored by the `Open Planning
michael@0 592 Project <http://openplans.org>`_ and is now maintained by a
michael@0 593 `group of developers <https://github.com/pypa/virtualenv/raw/master/AUTHORS.txt>`_.
michael@0 594 It is licensed under an
michael@0 595 `MIT-style permissive license <https://github.com/pypa/virtualenv/raw/master/LICENSE.txt>`_.

mercurial