blob: 6bf26ffe779e50f0448558bdf2d4610f76feb6a4 [file] [log] [blame]
Vinay Sajip7ded1f02012-05-26 03:45:29 +01001:mod:`venv` --- Creation of virtual environments
2================================================
3
4.. module:: venv
5 :synopsis: Creation of virtual environments.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Vinay Sajip7ded1f02012-05-26 03:45:29 +01007.. moduleauthor:: Vinay Sajip <vinay_sajip@yahoo.co.uk>
8.. sectionauthor:: Vinay Sajip <vinay_sajip@yahoo.co.uk>
9
Vinay Sajip7ded1f02012-05-26 03:45:29 +010010.. versionadded:: 3.3
11
Terry Jan Reedyfa089b92016-06-11 15:02:54 -040012**Source code:** :source:`Lib/venv/`
13
14.. index:: pair: Environments; virtual
Vinay Sajip7ded1f02012-05-26 03:45:29 +010015
16--------------
17
Georg Brandldbab58f2012-06-24 16:37:59 +020018The :mod:`venv` module provides support for creating lightweight "virtual
19environments" with their own site directories, optionally isolated from system
20site directories. Each virtual environment has its own Python binary (allowing
21creation of environments with various Python versions) and can have its own
22independent set of installed Python packages in its site directories.
23
Vinay Sajipa7045822013-09-06 09:50:43 +010024See :pep:`405` for more information about Python virtual environments.
Vinay Sajip7ded1f02012-05-26 03:45:29 +010025
26Creating virtual environments
27-----------------------------
28
Vinay Sajipc4618e32012-07-10 08:21:07 +010029.. include:: /using/venv-create.inc
Vinay Sajip7ded1f02012-05-26 03:45:29 +010030
Vinay Sajipa945ad12012-07-09 09:24:59 +010031
Vinay Sajipcd9b7462012-07-09 10:37:01 +010032.. _venv-def:
33
Brett Cannon15552c32016-07-08 10:46:21 -070034.. note:: A virtual environment is a Python environment such that the Python
35 interpreter, libraries and scripts installed into it are isolated from those
36 installed in other virtual environments, and (by default) any libraries
37 installed in a "system" Python, i.e., one which is installed as part of your
38 operating system.
Vinay Sajipa945ad12012-07-09 09:24:59 +010039
Brett Cannon15552c32016-07-08 10:46:21 -070040 A virtual environment is a directory tree which contains Python executable
41 files and other files which indicate that it is a virtual environment.
Vinay Sajipa945ad12012-07-09 09:24:59 +010042
Jason R. Coombs13266fb2014-05-12 22:40:49 -040043 Common installation tools such as ``Setuptools`` and ``pip`` work as
Brett Cannon15552c32016-07-08 10:46:21 -070044 expected with virtual environments. In other words, when a virtual
45 environment is active, they install Python packages into the virtual
46 environment without needing to be told to do so explicitly.
Vinay Sajipa945ad12012-07-09 09:24:59 +010047
Brett Cannon15552c32016-07-08 10:46:21 -070048 When a virtual environment is active (i.e., the virtual environment's Python
49 interpreter is running), the attributes :attr:`sys.prefix` and
50 :attr:`sys.exec_prefix` point to the base directory of the virtual
51 environment, whereas :attr:`sys.base_prefix` and
52 :attr:`sys.base_exec_prefix` point to the non-virtual environment Python
53 installation which was used to create the virtual environment. If a virtual
54 environment is not active, then :attr:`sys.prefix` is the same as
55 :attr:`sys.base_prefix` and :attr:`sys.exec_prefix` is the same as
56 :attr:`sys.base_exec_prefix` (they all point to a non-virtual environment
57 Python installation).
Vinay Sajipa945ad12012-07-09 09:24:59 +010058
Brett Cannon15552c32016-07-08 10:46:21 -070059 When a virtual environment is active, any options that change the
60 installation path will be ignored from all distutils configuration files to
61 prevent projects being inadvertently installed outside of the virtual
62 environment.
Georg Brandl521ed522013-05-12 12:36:07 +020063
Brett Cannon15552c32016-07-08 10:46:21 -070064 When working in a command shell, users can make a virtual environment active
65 by running an ``activate`` script in the virtual environment's executables
66 directory (the precise filename is shell-dependent), which prepends the
67 virtual environment's directory for executables to the ``PATH`` environment
68 variable for the running shell. There should be no need in other
69 circumstances to activate a virtual environment—scripts installed into
70 virtual environments have a "shebang" line which points to the virtual
71 environment's Python interpreter. This means that the script will run with
72 that interpreter regardless of the value of ``PATH``. On Windows, "shebang"
73 line processing is supported if you have the Python Launcher for Windows
74 installed (this was added to Python in 3.3 - see :pep:`397` for more
75 details). Thus, double-clicking an installed script in a Windows Explorer
76 window should run the script with the correct interpreter without there
77 needing to be any reference to its virtual environment in ``PATH``.
Vinay Sajipa7045822013-09-06 09:50:43 +010078
Vinay Sajip7ded1f02012-05-26 03:45:29 +010079
Larry Hastings3732ed22014-03-15 21:13:56 -070080.. _venv-api:
81
Vinay Sajip7ded1f02012-05-26 03:45:29 +010082API
83---
84
Vinay Sajip7ded1f02012-05-26 03:45:29 +010085.. highlight:: python
86
Georg Brandldbab58f2012-06-24 16:37:59 +020087The high-level method described above makes use of a simple API which provides
88mechanisms for third-party virtual environment creators to customize environment
89creation according to their needs, the :class:`EnvBuilder` class.
Vinay Sajip7ded1f02012-05-26 03:45:29 +010090
Nick Coghlan8fbdb092013-11-23 00:30:34 +100091.. class:: EnvBuilder(system_site_packages=False, clear=False, \
Vinay Sajipfd0f84b2016-08-06 10:43:44 +010092 symlinks=False, upgrade=False, with_pip=False, \
93 prompt=None)
Vinay Sajip7ded1f02012-05-26 03:45:29 +010094
Georg Brandldbab58f2012-06-24 16:37:59 +020095 The :class:`EnvBuilder` class accepts the following keyword arguments on
96 instantiation:
Vinay Sajip7ded1f02012-05-26 03:45:29 +010097
Georg Brandldbab58f2012-06-24 16:37:59 +020098 * ``system_site_packages`` -- a Boolean value indicating that the system Python
99 site-packages should be available to the environment (defaults to ``False``).
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100100
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200101 * ``clear`` -- a Boolean value which, if true, will delete the contents of
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100102 any existing target directory, before creating the environment.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100103
Georg Brandldbab58f2012-06-24 16:37:59 +0200104 * ``symlinks`` -- a Boolean value indicating whether to attempt to symlink the
105 Python binary (and any necessary DLLs or other binaries,
106 e.g. ``pythonw.exe``), rather than copying. Defaults to ``True`` on Linux and
Vinay Sajip90db6612012-07-17 17:33:46 +0100107 Unix systems, but ``False`` on Windows.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100108
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200109 * ``upgrade`` -- a Boolean value which, if true, will upgrade an existing
Vinay Sajipa945ad12012-07-09 09:24:59 +0100110 environment with the running Python - for use when that Python has been
111 upgraded in-place (defaults to ``False``).
112
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200113 * ``with_pip`` -- a Boolean value which, if true, ensures pip is
Nick Coghlanaa029da2014-02-09 10:10:24 +1000114 installed in the virtual environment. This uses :mod:`ensurepip` with
115 the ``--default-pip`` option.
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000116
Vinay Sajipfd0f84b2016-08-06 10:43:44 +0100117 * ``prompt`` -- a String to be used after virtual environment is activated
118 (defaults to ``None`` which means directory name of the environment would
119 be used).
120
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000121 .. versionchanged:: 3.4
122 Added the ``with_pip`` parameter
123
Vinay Sajipfd0f84b2016-08-06 10:43:44 +0100124 .. versionadded:: 3.6
125 Added the ``prompt`` parameter
126
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100127
Georg Brandldbab58f2012-06-24 16:37:59 +0200128 Creators of third-party virtual environment tools will be free to use the
129 provided ``EnvBuilder`` class as a base class.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100130
Georg Brandldbab58f2012-06-24 16:37:59 +0200131 The returned env-builder is an object which has a method, ``create``:
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100132
Georg Brandldbab58f2012-06-24 16:37:59 +0200133 .. method:: create(env_dir)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100134
Georg Brandldbab58f2012-06-24 16:37:59 +0200135 This method takes as required argument the path (absolute or relative to
136 the current directory) of the target directory which is to contain the
137 virtual environment. The ``create`` method will either create the
138 environment in the specified directory, or raise an appropriate
139 exception.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100140
Georg Brandldbab58f2012-06-24 16:37:59 +0200141 The ``create`` method of the ``EnvBuilder`` class illustrates the hooks
142 available for subclass customization::
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100143
Georg Brandldbab58f2012-06-24 16:37:59 +0200144 def create(self, env_dir):
145 """
146 Create a virtualized Python environment in a directory.
147 env_dir is the target directory to create an environment in.
148 """
149 env_dir = os.path.abspath(env_dir)
Georg Brandla0b79232013-10-06 12:52:49 +0200150 context = self.ensure_directories(env_dir)
Georg Brandldbab58f2012-06-24 16:37:59 +0200151 self.create_configuration(context)
152 self.setup_python(context)
153 self.setup_scripts(context)
154 self.post_setup(context)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100155
Georg Brandla0b79232013-10-06 12:52:49 +0200156 Each of the methods :meth:`ensure_directories`,
Georg Brandldbab58f2012-06-24 16:37:59 +0200157 :meth:`create_configuration`, :meth:`setup_python`,
158 :meth:`setup_scripts` and :meth:`post_setup` can be overridden.
159
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100160 .. method:: ensure_directories(env_dir)
Georg Brandldbab58f2012-06-24 16:37:59 +0200161
162 Creates the environment directory and all necessary directories, and
163 returns a context object. This is just a holder for attributes (such as
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100164 paths), for use by the other methods. The directories are allowed to
165 exist already, as long as either ``clear`` or ``upgrade`` were
166 specified to allow operating on an existing environment directory.
Georg Brandldbab58f2012-06-24 16:37:59 +0200167
168 .. method:: create_configuration(context)
169
170 Creates the ``pyvenv.cfg`` configuration file in the environment.
171
172 .. method:: setup_python(context)
173
174 Creates a copy of the Python executable (and, under Windows, DLLs) in
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100175 the environment. On a POSIX system, if a specific executable
176 ``python3.x`` was used, symlinks to ``python`` and ``python3`` will be
177 created pointing to that executable, unless files with those names
178 already exist.
Georg Brandldbab58f2012-06-24 16:37:59 +0200179
180 .. method:: setup_scripts(context)
181
182 Installs activation scripts appropriate to the platform into the virtual
183 environment.
184
185 .. method:: post_setup(context)
186
187 A placeholder method which can be overridden in third party
188 implementations to pre-install packages in the virtual environment or
189 perform other post-creation steps.
190
191 In addition, :class:`EnvBuilder` provides this utility method that can be
192 called from :meth:`setup_scripts` or :meth:`post_setup` in subclasses to
193 assist in installing custom scripts into the virtual environment.
194
195 .. method:: install_scripts(context, path)
196
197 *path* is the path to a directory that should contain subdirectories
198 "common", "posix", "nt", each containing scripts destined for the bin
199 directory in the environment. The contents of "common" and the
200 directory corresponding to :data:`os.name` are copied after some text
201 replacement of placeholders:
202
203 * ``__VENV_DIR__`` is replaced with the absolute path of the environment
204 directory.
205
206 * ``__VENV_NAME__`` is replaced with the environment name (final path
207 segment of environment directory).
208
Vinay Sajipdff9e252013-10-02 11:36:16 +0100209 * ``__VENV_PROMPT__`` is replaced with the prompt (the environment
210 name surrounded by parentheses and with a following space)
211
Georg Brandldbab58f2012-06-24 16:37:59 +0200212 * ``__VENV_BIN_NAME__`` is replaced with the name of the bin directory
213 (either ``bin`` or ``Scripts``).
214
215 * ``__VENV_PYTHON__`` is replaced with the absolute path of the
216 environment's executable.
217
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100218 The directories are allowed to exist (for when an existing environment
219 is being upgraded).
Georg Brandldbab58f2012-06-24 16:37:59 +0200220
221There is also a module-level convenience function:
222
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000223.. function:: create(env_dir, system_site_packages=False, clear=False, \
224 symlinks=False, with_pip=False)
Georg Brandldbab58f2012-06-24 16:37:59 +0200225
226 Create an :class:`EnvBuilder` with the given keyword arguments, and call its
227 :meth:`~EnvBuilder.create` method with the *env_dir* argument.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000228
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000229 .. versionchanged:: 3.4
230 Added the ``with_pip`` parameter
231
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000232An example of extending ``EnvBuilder``
233--------------------------------------
234
235The following script shows how to extend :class:`EnvBuilder` by implementing a
Brett Cannon15552c32016-07-08 10:46:21 -0700236subclass which installs setuptools and pip into a created virtual environment::
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000237
238 import os
239 import os.path
240 from subprocess import Popen, PIPE
241 import sys
242 from threading import Thread
243 from urllib.parse import urlparse
244 from urllib.request import urlretrieve
245 import venv
246
Vinay Sajip3c557f22013-07-12 20:54:25 +0100247 class ExtendedEnvBuilder(venv.EnvBuilder):
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000248 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100249 This builder installs setuptools and pip so that you can pip or
Brett Cannon15552c32016-07-08 10:46:21 -0700250 easy_install other packages into the created virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000251
Vinay Sajip3c557f22013-07-12 20:54:25 +0100252 :param nodist: If True, setuptools and pip are not installed into the
Brett Cannon15552c32016-07-08 10:46:21 -0700253 created virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000254 :param nopip: If True, pip is not installed into the created
Brett Cannon15552c32016-07-08 10:46:21 -0700255 virtual environment.
Vinay Sajip3c557f22013-07-12 20:54:25 +0100256 :param progress: If setuptools or pip are installed, the progress of the
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000257 installation can be monitored by passing a progress
258 callable. If specified, it is called with two
259 arguments: a string indicating some progress, and a
260 context indicating where the string is coming from.
261 The context argument can have one of three values:
262 'main', indicating that it is called from virtualize()
263 itself, and 'stdout' and 'stderr', which are obtained
264 by reading lines from the output streams of a subprocess
265 which is used to install the app.
266
267 If a callable is not specified, default progress
268 information is output to sys.stderr.
269 """
270
271 def __init__(self, *args, **kwargs):
272 self.nodist = kwargs.pop('nodist', False)
273 self.nopip = kwargs.pop('nopip', False)
274 self.progress = kwargs.pop('progress', None)
275 self.verbose = kwargs.pop('verbose', False)
276 super().__init__(*args, **kwargs)
277
278 def post_setup(self, context):
279 """
280 Set up any packages which need to be pre-installed into the
Brett Cannon15552c32016-07-08 10:46:21 -0700281 virtual environment being created.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000282
Brett Cannon15552c32016-07-08 10:46:21 -0700283 :param context: The information for the virtual environment
284 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000285 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100286 os.environ['VIRTUAL_ENV'] = context.env_dir
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000287 if not self.nodist:
Vinay Sajip3c557f22013-07-12 20:54:25 +0100288 self.install_setuptools(context)
289 # Can't install pip without setuptools
290 if not self.nopip and not self.nodist:
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000291 self.install_pip(context)
292
293 def reader(self, stream, context):
294 """
295 Read lines from a subprocess' output stream and either pass to a progress
296 callable (if specified) or write progress information to sys.stderr.
297 """
298 progress = self.progress
299 while True:
300 s = stream.readline()
301 if not s:
302 break
303 if progress is not None:
304 progress(s, context)
305 else:
306 if not self.verbose:
307 sys.stderr.write('.')
308 else:
309 sys.stderr.write(s.decode('utf-8'))
310 sys.stderr.flush()
Vinay Sajipad6bb032013-07-12 21:44:35 +0100311 stream.close()
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000312
313 def install_script(self, context, name, url):
314 _, _, path, _, _, _ = urlparse(url)
315 fn = os.path.split(path)[-1]
316 binpath = context.bin_path
317 distpath = os.path.join(binpath, fn)
Brett Cannon15552c32016-07-08 10:46:21 -0700318 # Download script into the virtual environment's binaries folder
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000319 urlretrieve(url, distpath)
320 progress = self.progress
Vinay Sajip3c557f22013-07-12 20:54:25 +0100321 if self.verbose:
322 term = '\n'
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000323 else:
Vinay Sajip3c557f22013-07-12 20:54:25 +0100324 term = ''
325 if progress is not None:
326 progress('Installing %s ...%s' % (name, term), 'main')
327 else:
328 sys.stderr.write('Installing %s ...%s' % (name, term))
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000329 sys.stderr.flush()
Brett Cannon15552c32016-07-08 10:46:21 -0700330 # Install in the virtual environment
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000331 args = [context.env_exe, fn]
332 p = Popen(args, stdout=PIPE, stderr=PIPE, cwd=binpath)
333 t1 = Thread(target=self.reader, args=(p.stdout, 'stdout'))
334 t1.start()
335 t2 = Thread(target=self.reader, args=(p.stderr, 'stderr'))
336 t2.start()
337 p.wait()
338 t1.join()
339 t2.join()
340 if progress is not None:
341 progress('done.', 'main')
342 else:
343 sys.stderr.write('done.\n')
344 # Clean up - no longer needed
345 os.unlink(distpath)
346
Vinay Sajip3c557f22013-07-12 20:54:25 +0100347 def install_setuptools(self, context):
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000348 """
Brett Cannon15552c32016-07-08 10:46:21 -0700349 Install setuptools in the virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000350
Brett Cannon15552c32016-07-08 10:46:21 -0700351 :param context: The information for the virtual environment
352 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000353 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100354 url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
355 self.install_script(context, 'setuptools', url)
356 # clear up the setuptools archive which gets downloaded
357 pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000358 files = filter(pred, os.listdir(context.bin_path))
359 for f in files:
360 f = os.path.join(context.bin_path, f)
361 os.unlink(f)
362
363 def install_pip(self, context):
364 """
Brett Cannon15552c32016-07-08 10:46:21 -0700365 Install pip in the virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000366
Brett Cannon15552c32016-07-08 10:46:21 -0700367 :param context: The information for the virtual environment
368 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000369 """
370 url = 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py'
371 self.install_script(context, 'pip', url)
372
373 def main(args=None):
374 compatible = True
375 if sys.version_info < (3, 3):
376 compatible = False
377 elif not hasattr(sys, 'base_prefix'):
378 compatible = False
379 if not compatible:
380 raise ValueError('This script is only for use with '
381 'Python 3.3 or later')
382 else:
383 import argparse
384
385 parser = argparse.ArgumentParser(prog=__name__,
386 description='Creates virtual Python '
387 'environments in one or '
388 'more target '
389 'directories.')
390 parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
Brett Cannon15552c32016-07-08 10:46:21 -0700391 help='A directory in which to create the
392 'virtual environment.')
Vinay Sajip3c557f22013-07-12 20:54:25 +0100393 parser.add_argument('--no-setuptools', default=False,
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000394 action='store_true', dest='nodist',
Vinay Sajip3c557f22013-07-12 20:54:25 +0100395 help="Don't install setuptools or pip in the "
396 "virtual environment.")
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000397 parser.add_argument('--no-pip', default=False,
398 action='store_true', dest='nopip',
399 help="Don't install pip in the virtual "
400 "environment.")
401 parser.add_argument('--system-site-packages', default=False,
402 action='store_true', dest='system_site',
403 help='Give the virtual environment access to the '
404 'system site-packages dir.')
405 if os.name == 'nt':
406 use_symlinks = False
407 else:
408 use_symlinks = True
409 parser.add_argument('--symlinks', default=use_symlinks,
410 action='store_true', dest='symlinks',
411 help='Try to use symlinks rather than copies, '
412 'when symlinks are not the default for '
413 'the platform.')
414 parser.add_argument('--clear', default=False, action='store_true',
415 dest='clear', help='Delete the contents of the '
Brett Cannon15552c32016-07-08 10:46:21 -0700416 'virtual environment '
417 'directory if it already '
418 'exists, before virtual '
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000419 'environment creation.')
420 parser.add_argument('--upgrade', default=False, action='store_true',
Brett Cannon15552c32016-07-08 10:46:21 -0700421 dest='upgrade', help='Upgrade the virtual '
422 'environment directory to '
423 'use this version of '
424 'Python, assuming Python '
425 'has been upgraded '
426 'in-place.')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000427 parser.add_argument('--verbose', default=False, action='store_true',
428 dest='verbose', help='Display the output '
429 'from the scripts which '
Vinay Sajip3c557f22013-07-12 20:54:25 +0100430 'install setuptools and pip.')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000431 options = parser.parse_args(args)
432 if options.upgrade and options.clear:
433 raise ValueError('you cannot supply --upgrade and --clear together.')
Vinay Sajip3c557f22013-07-12 20:54:25 +0100434 builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000435 clear=options.clear,
436 symlinks=options.symlinks,
437 upgrade=options.upgrade,
438 nodist=options.nodist,
439 nopip=options.nopip,
440 verbose=options.verbose)
441 for d in options.dirs:
442 builder.create(d)
443
444 if __name__ == '__main__':
445 rc = 1
446 try:
447 main()
448 rc = 0
449 except Exception as e:
450 print('Error: %s' % e, file=sys.stderr)
451 sys.exit(rc)
452
Vinay Sajip3c557f22013-07-12 20:54:25 +0100453
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000454This script is also available for download `online
455<https://gist.github.com/4673395>`_.