1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
|
Metadata-Version: 1.0
Name: virtualenv
Version: 1.1
Summary: Virtual Python Environment builder
Home-page: http://pypi.python.org/pypi/virtualenv
Author: Ian Bicking
Author-email: ianb@colorstudy.com
License: MIT
Description: virtualenv
==========
* `Discussion list <http://groups.google.com/group/python-virtualenv/>`_
* `Bugs <https://bugs.launchpad.net/virtualenv/>`_
.. contents::
Status and License
------------------
``virtualenv`` is a successor to `workingenv
<http://cheeseshop.python.org/pypi/workingenv.py>`_, and an extension
of `virtual-python
<http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python>`_.
It is written by Ian Bicking, and sponsored by the `Open Planning
Project <http://topp.openplans.org>`_. It is licensed under an
`MIT-style permissive license
<http://svn.colorstudy.com/virtualenv/trunk/docs/license.txt>`_.
You can install it with ``easy_install virtualenv``, or from the
`subversion repository
<http://svn.colorstudy.com/virtualenv/trunk#egg=virtualenv-dev>`_ with
``easy_install virtualenv==dev``.
What It Does
------------
``virtualenv`` is a tool to create isolated Python environments.
The basic problem being addressed is one of dependencies and versions,
and indirectly permissions. Imagine you have an application that
needs version 1 of LibFoo, but another application requires version
2. How can you use both these applications? If you install
everything into ``/usr/lib/python2.4/site-packages`` (or whatever your
platform's standard location is), it's easy to end up in a situation
where you unintentionally upgrade an application that shouldn't be
upgraded.
Or more generally, what if you want to install an application *and
leave it be*? If an application works, any change in its libraries or
the versions of those libraries can break the application.
Also, what if you can't install packages into the global
``site-packages`` directory? For instance, on a shared host.
In all these cases, ``virtualenv`` can help you. It creates an
environment that has its own installation directories, that doesn't
share libraries with other virtualenv environments (and optionally
doesn't use the globally installed libraries either).
The basic usage is::
$ python virtualenv.py ENV
This creates ``ENV/lib/python2.4/site-packages`` (or
``ENV/lib/python2.5/site-packages`` on Python 2.5, etc), where any
libraries you install will go. It also creates ``ENV/bin/python``,
which is a Python interpreter that uses this environment. Anytime you
use that interpreter (including when a script has
``#!/path/to/ENV/bin/python`` in it) the libraries in that environment
will be used. (**Note for Windows:** scripts and executables on
Windows go in ``ENV\Scripts\``; everywhere you see ``bin/`` replace it
with ``Scripts\``)
It also installs `Setuptools
<http://peak.telecommunity.com/DevCenter/setuptools>`_ for you, and if
you use ``ENV/bin/easy_install`` the packages will be installed into
the environment.
Creating Your Own Bootstrap Scripts
-----------------------------------
While this creates an environment, it doesn't put anything into the
environment. Developers may find it useful to distribute a script
that sets up a particular environment, for example a script that
installs a particular web application.
To create a script like this, call
``virtualenv.create_bootstrap_script(extra_text)``, and write the
result to your new bootstrapping script. Here's the documentation
from the docstring:
Creates a bootstrap script, which is like this script but with
extend_parser, adjust_options, and after_install hooks.
This returns a string that (written to disk of course) can be used
as a bootstrap script with your own customizations. The script
will be the standard virtualenv.py script, with your extra text
added (your extra text should be Python code).
If you include these functions, they will be called:
``extend_parser(optparse_parser)``:
You can add or remove options from the parser here.
``adjust_options(options, args)``:
You can change options here, or change the args (if you accept
different kinds of arguments, be sure you modify ``args`` so it is
only ``[DEST_DIR]``).
``after_install(options, home_dir)``:
After everything is installed, this function is called. This
is probably the function you are most likely to use. An
example would be::
def after_install(options, home_dir):
subprocess.call([join(home_dir, 'bin', 'easy_install'),
'MyPackage'])
subprocess.call([join(home_dir, 'bin', 'my-package-script'),
'setup', home_dir])
This example immediately installs a package, and runs a setup
script from that package.
Bootstrap Example
~~~~~~~~~~~~~~~~~
Here's a more concrete example of how you could use this::
import virtualenv, textwrap
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
import os, subprocess
def after_install(options, home_dir):
etc = join(home_dir, 'etc')
if not os.path.exists(etc):
os.makedirs(etc)
subprocess.call([join(home_dir, 'bin', 'easy_install'),
'BlogApplication'])
subprocess.call([join(home_dir, 'bin', 'paster'),
'make-config', 'BlogApplication',
join(etc, 'blog.ini')])
subprocess.call([join(home_dir, 'bin', 'paster'),
'setup-app', join(etc, 'blog.ini')])
"""))
f = open('blog-bootstrap.py', 'w').write(output)
Another example is available `here
<https://svn.openplans.org/svn/fassembler/trunk/fassembler/create-venv-script.py>`_.
activate script
~~~~~~~~~~~~~~~
In a newly created virtualenv there will be a ``bin/activate`` shell
script, or a ``Scripts/activate.bat`` batch file on Windows.
On Posix systems you can do::
$ source bin/activate
This will change your ``$PATH`` to point to the virtualenv ``bin/``
directory, and update your prompt. Unlike workingenv, this is all it
does; it's a convenience. But if you use the complete path like
``/path/to/env/bin/python script.py`` you do not need to activate the
environment first. You have to use ``source`` because it changes the
environment in-place. After activating an environment you can use the
function ``deactivate`` to undo the changes.
On Windows you just do::
> \path\to\env\bin\activate.bat
And use ``deactivate.bat`` to undo the changes.
The ``--no-site-packages`` Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you build with ``virtualenv --no-site-packages ENV`` it will *not*
inherit any packages from ``/usr/lib/python2.5/site-packages`` (or
wherever your global site-packages directory is). This can be used if
you don't have control over site-packages and don't want to depend on
the packages there, or you just want more isolation from the global
system.
Using Virtualenv without ``bin/python``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sometimes you can't or don't want to use the Python interpreter
created by the virtualenv. For instance, in a `mod_python
<http://www.modpython.org/>`_ or `mod_wsgi <http://www.modwsgi.org/>`_
environment, there is only one interpreter.
Luckily, it's easy. You must use the custom Python interpreter to
*install* libraries. But to *use* libraries, you just have to be sure
the path is correct. Adding the correct path is easy::
import site
site.addsitedir('/path/to/virtualenv/lib/python2.5/site-packages')
Using this you can have your isolated working environment, using the
custom Python interpreter, but treat the result as just a simple set
of libraries when running your application.
Compare & Contrast with Alternatives
------------------------------------
There are several alternatives that create isolated environments:
* ``workingenv`` (which I do not suggest you use anymore *if*
virtualenv works on your platform) is the predecessor to this
library. It used the main Python interpreter, but relied on setting
``$PYTHONPATH`` to activate the environment. This causes problems
when running Python scripts that aren't part of the environment
(e.g., a globally installed ``hg`` or ``bzr``). It also conflicted
a lot with Setuptools.
* `virtual-python
<http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python>`_
is also a predecessor to this library. It uses only symlinks, so it
couldn't work on Windows. It also symlinks over the *entire*
standard library and global ``site-packages``. As a result, it
won't see new additions to the global ``site-packages``.
This script only symlinks a small portion of the standard library
into the environment, and so Windows it is feasible to simply copy
these files over. Also, it creates a new/empty ``site-packages``
and also adds the global ``site-packages`` to the path, so updates
are tracked separately. This script also installs Setuptools
automatically, saving a step and avoiding the need for network
access.
* `zc.buildout <http://pypi.python.org/pypi/zc.buildout>`_ doesn't
create an isolated Python environment in the same style, but
achieves similar results through a declarative config file that sets
up scripts with very particular packages. As a declarative system,
it is somewhat easier to repeat and manage, but more difficult to
experiment with. ``zc.buildout`` includes the ability to setup
non-Python systems (e.g., a database server or an Apache instance).
I *strongly* recommend anyone doing application development or
deployment use one of these tools.
Other Documentation
-------------------
* James Gardner has written a tutorial on using `virtualenv with
Pylons
<http://wiki.pylonshq.com/display/pylonscookbook/Using+a+Virtualenv+Sandbox>`_.
* `Blog announcement
<http://blog.ianbicking.org/2007/10/10/workingenv-is-dead-long-live-virtualenv/>`_.
Changes & News
--------------
1.1
~~~
* Added support for Python 2.6.
* Fix a problem with missing ``DLLs/zlib.pyd`` on Windows. Create
* ``bin/python`` (or ``bin/python.exe``) even when you run virtualenv
with an interpreter named, e.g., ``python2.4``
* Fix MacPorts Python
* Added --unzip-setuptools option
* Update to Setuptools 0.6c8
* If the current directory is not writable, run ez_setup.py in ``/tmp``
* Copy or symlink over the ``include`` directory so that packages will
more consistently compile.
1.0
~~~
* Fix build on systems that use ``/usr/lib64``, distinct from
``/usr/lib`` (specifically CentOS x64).
* Fixed bug in ``--clear``.
* Fixed typos in ``deactivate.bat``.
* Preserve ``$PYTHONPATH`` when calling subprocesses.
0.9.2
~~~~~
* Fix include dir copying on Windows (makes compiling possible).
* Include the main ``lib-tk`` in the path.
* Patch ``distutils.sysconfig``: ``get_python_inc`` and
``get_python_lib`` to point to the global locations.
* Install ``distutils.cfg`` before Setuptools, so that system
customizations of ``distutils.cfg`` won't effect the installation.
* Add ``bin/pythonX.Y`` to the virtualenv (in addition to
``bin/python``).
* Fixed an issue with Mac Framework Python builds, and absolute paths
(from Ronald Oussoren).
0.9.1
~~~~~
* Improve ability to create a virtualenv from inside a virtualenv.
* Fix a little bug in ``bin/activate``.
* Actually get ``distutils.cfg`` to work reliably.
0.9
~~~
* Added ``lib-dynload`` and ``config`` to things that need to be
copied over in an environment.
* Copy over or symlink the ``include`` directory, so that you can
build packages that need the C headers.
* Include a ``distutils`` package, so you can locally update
``distutils.cfg`` (in ``lib/pythonX.Y/distutils/distutils.cfg``).
* Better avoid downloading Setuptools, and hitting PyPI on environment
creation.
* Fix a problem creating a ``lib64/`` directory.
* Should work on MacOSX Framework builds (the default Python
installations on Mac). Thanks to Ronald Oussoren.
0.8.4
~~~~~
* Windows installs would sometimes give errors about ``sys.prefix`` that
were inaccurate.
* Slightly prettier output.
0.8.3
~~~~~
* Added support for Windows.
0.8.2
~~~~~
* Give a better warning if you are on an unsupported platform (Mac
Framework Pythons, and Windows).
* Give error about running while inside a workingenv.
* Give better error message about Python 2.3.
0.8.1
~~~~~
Fixed packaging of the library.
0.8
~~~
Initial release. Everything is changed and new!
Keywords: setuptools deployment installation distutils
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
|