blob: 1fff7bc4bfb22be7be57a3d07b74e590ac5d3378 [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
Brett Cannonf8c15052016-10-21 12:53:40 -070026
27
Vinay Sajip7ded1f02012-05-26 03:45:29 +010028Creating virtual environments
29-----------------------------
30
Vinay Sajipc4618e32012-07-10 08:21:07 +010031.. include:: /using/venv-create.inc
Vinay Sajip7ded1f02012-05-26 03:45:29 +010032
Vinay Sajipa945ad12012-07-09 09:24:59 +010033
Vinay Sajipcd9b7462012-07-09 10:37:01 +010034.. _venv-def:
35
Brett Cannon15552c32016-07-08 10:46:21 -070036.. note:: A virtual environment is a Python environment such that the Python
37 interpreter, libraries and scripts installed into it are isolated from those
38 installed in other virtual environments, and (by default) any libraries
39 installed in a "system" Python, i.e., one which is installed as part of your
40 operating system.
Vinay Sajipa945ad12012-07-09 09:24:59 +010041
Brett Cannon15552c32016-07-08 10:46:21 -070042 A virtual environment is a directory tree which contains Python executable
43 files and other files which indicate that it is a virtual environment.
Vinay Sajipa945ad12012-07-09 09:24:59 +010044
Jason R. Coombs13266fb2014-05-12 22:40:49 -040045 Common installation tools such as ``Setuptools`` and ``pip`` work as
Brett Cannon15552c32016-07-08 10:46:21 -070046 expected with virtual environments. In other words, when a virtual
47 environment is active, they install Python packages into the virtual
48 environment without needing to be told to do so explicitly.
Vinay Sajipa945ad12012-07-09 09:24:59 +010049
Brett Cannon15552c32016-07-08 10:46:21 -070050 When a virtual environment is active (i.e., the virtual environment's Python
51 interpreter is running), the attributes :attr:`sys.prefix` and
52 :attr:`sys.exec_prefix` point to the base directory of the virtual
53 environment, whereas :attr:`sys.base_prefix` and
54 :attr:`sys.base_exec_prefix` point to the non-virtual environment Python
55 installation which was used to create the virtual environment. If a virtual
56 environment is not active, then :attr:`sys.prefix` is the same as
57 :attr:`sys.base_prefix` and :attr:`sys.exec_prefix` is the same as
58 :attr:`sys.base_exec_prefix` (they all point to a non-virtual environment
59 Python installation).
Vinay Sajipa945ad12012-07-09 09:24:59 +010060
Brett Cannon15552c32016-07-08 10:46:21 -070061 When a virtual environment is active, any options that change the
62 installation path will be ignored from all distutils configuration files to
63 prevent projects being inadvertently installed outside of the virtual
64 environment.
Georg Brandl521ed522013-05-12 12:36:07 +020065
Brett Cannon15552c32016-07-08 10:46:21 -070066 When working in a command shell, users can make a virtual environment active
67 by running an ``activate`` script in the virtual environment's executables
68 directory (the precise filename is shell-dependent), which prepends the
69 virtual environment's directory for executables to the ``PATH`` environment
70 variable for the running shell. There should be no need in other
71 circumstances to activate a virtual environment—scripts installed into
72 virtual environments have a "shebang" line which points to the virtual
73 environment's Python interpreter. This means that the script will run with
74 that interpreter regardless of the value of ``PATH``. On Windows, "shebang"
75 line processing is supported if you have the Python Launcher for Windows
76 installed (this was added to Python in 3.3 - see :pep:`397` for more
77 details). Thus, double-clicking an installed script in a Windows Explorer
78 window should run the script with the correct interpreter without there
79 needing to be any reference to its virtual environment in ``PATH``.
Vinay Sajipa7045822013-09-06 09:50:43 +010080
Vinay Sajip7ded1f02012-05-26 03:45:29 +010081
Larry Hastings3732ed22014-03-15 21:13:56 -070082.. _venv-api:
83
Vinay Sajip7ded1f02012-05-26 03:45:29 +010084API
85---
86
Vinay Sajip7ded1f02012-05-26 03:45:29 +010087.. highlight:: python
88
Georg Brandldbab58f2012-06-24 16:37:59 +020089The high-level method described above makes use of a simple API which provides
90mechanisms for third-party virtual environment creators to customize environment
91creation according to their needs, the :class:`EnvBuilder` class.
Vinay Sajip7ded1f02012-05-26 03:45:29 +010092
Nick Coghlan8fbdb092013-11-23 00:30:34 +100093.. class:: EnvBuilder(system_site_packages=False, clear=False, \
Vinay Sajipfd0f84b2016-08-06 10:43:44 +010094 symlinks=False, upgrade=False, with_pip=False, \
95 prompt=None)
Vinay Sajip7ded1f02012-05-26 03:45:29 +010096
Georg Brandldbab58f2012-06-24 16:37:59 +020097 The :class:`EnvBuilder` class accepts the following keyword arguments on
98 instantiation:
Vinay Sajip7ded1f02012-05-26 03:45:29 +010099
Georg Brandldbab58f2012-06-24 16:37:59 +0200100 * ``system_site_packages`` -- a Boolean value indicating that the system Python
101 site-packages should be available to the environment (defaults to ``False``).
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100102
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200103 * ``clear`` -- a Boolean value which, if true, will delete the contents of
Vinay Sajipbd40d3e2012-10-11 17:22:45 +0100104 any existing target directory, before creating the environment.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100105
Georg Brandldbab58f2012-06-24 16:37:59 +0200106 * ``symlinks`` -- a Boolean value indicating whether to attempt to symlink the
107 Python binary (and any necessary DLLs or other binaries,
108 e.g. ``pythonw.exe``), rather than copying. Defaults to ``True`` on Linux and
Vinay Sajip90db6612012-07-17 17:33:46 +0100109 Unix systems, but ``False`` on Windows.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100110
Serhiy Storchakafbc1c262013-11-29 12:17:13 +0200111 * ``upgrade`` -- a Boolean value which, if true, will upgrade an existing
Vinay Sajipa945ad12012-07-09 09:24:59 +0100112 environment with the running Python - for use when that Python has been
113 upgraded in-place (defaults to ``False``).
114
Serhiy Storchaka0e90e992013-11-29 12:19:53 +0200115 * ``with_pip`` -- a Boolean value which, if true, ensures pip is
Nick Coghlanaa029da2014-02-09 10:10:24 +1000116 installed in the virtual environment. This uses :mod:`ensurepip` with
117 the ``--default-pip`` option.
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000118
Vinay Sajipfd0f84b2016-08-06 10:43:44 +0100119 * ``prompt`` -- a String to be used after virtual environment is activated
120 (defaults to ``None`` which means directory name of the environment would
121 be used).
122
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000123 .. versionchanged:: 3.4
124 Added the ``with_pip`` parameter
125
Vinay Sajipfd0f84b2016-08-06 10:43:44 +0100126 .. versionadded:: 3.6
127 Added the ``prompt`` parameter
128
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100129
Georg Brandldbab58f2012-06-24 16:37:59 +0200130 Creators of third-party virtual environment tools will be free to use the
131 provided ``EnvBuilder`` class as a base class.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100132
Georg Brandldbab58f2012-06-24 16:37:59 +0200133 The returned env-builder is an object which has a method, ``create``:
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100134
Georg Brandldbab58f2012-06-24 16:37:59 +0200135 .. method:: create(env_dir)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100136
Georg Brandldbab58f2012-06-24 16:37:59 +0200137 This method takes as required argument the path (absolute or relative to
138 the current directory) of the target directory which is to contain the
139 virtual environment. The ``create`` method will either create the
140 environment in the specified directory, or raise an appropriate
141 exception.
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100142
Georg Brandldbab58f2012-06-24 16:37:59 +0200143 The ``create`` method of the ``EnvBuilder`` class illustrates the hooks
144 available for subclass customization::
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100145
Georg Brandldbab58f2012-06-24 16:37:59 +0200146 def create(self, env_dir):
147 """
148 Create a virtualized Python environment in a directory.
149 env_dir is the target directory to create an environment in.
150 """
151 env_dir = os.path.abspath(env_dir)
Georg Brandla0b79232013-10-06 12:52:49 +0200152 context = self.ensure_directories(env_dir)
Georg Brandldbab58f2012-06-24 16:37:59 +0200153 self.create_configuration(context)
154 self.setup_python(context)
155 self.setup_scripts(context)
156 self.post_setup(context)
Vinay Sajip7ded1f02012-05-26 03:45:29 +0100157
Georg Brandla0b79232013-10-06 12:52:49 +0200158 Each of the methods :meth:`ensure_directories`,
Georg Brandldbab58f2012-06-24 16:37:59 +0200159 :meth:`create_configuration`, :meth:`setup_python`,
160 :meth:`setup_scripts` and :meth:`post_setup` can be overridden.
161
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100162 .. method:: ensure_directories(env_dir)
Georg Brandldbab58f2012-06-24 16:37:59 +0200163
164 Creates the environment directory and all necessary directories, and
165 returns a context object. This is just a holder for attributes (such as
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100166 paths), for use by the other methods. The directories are allowed to
167 exist already, as long as either ``clear`` or ``upgrade`` were
168 specified to allow operating on an existing environment directory.
Georg Brandldbab58f2012-06-24 16:37:59 +0200169
170 .. method:: create_configuration(context)
171
172 Creates the ``pyvenv.cfg`` configuration file in the environment.
173
174 .. method:: setup_python(context)
175
176 Creates a copy of the Python executable (and, under Windows, DLLs) in
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100177 the environment. On a POSIX system, if a specific executable
178 ``python3.x`` was used, symlinks to ``python`` and ``python3`` will be
179 created pointing to that executable, unless files with those names
180 already exist.
Georg Brandldbab58f2012-06-24 16:37:59 +0200181
182 .. method:: setup_scripts(context)
183
184 Installs activation scripts appropriate to the platform into the virtual
185 environment.
186
187 .. method:: post_setup(context)
188
189 A placeholder method which can be overridden in third party
190 implementations to pre-install packages in the virtual environment or
191 perform other post-creation steps.
192
193 In addition, :class:`EnvBuilder` provides this utility method that can be
194 called from :meth:`setup_scripts` or :meth:`post_setup` in subclasses to
195 assist in installing custom scripts into the virtual environment.
196
197 .. method:: install_scripts(context, path)
198
199 *path* is the path to a directory that should contain subdirectories
200 "common", "posix", "nt", each containing scripts destined for the bin
201 directory in the environment. The contents of "common" and the
202 directory corresponding to :data:`os.name` are copied after some text
203 replacement of placeholders:
204
205 * ``__VENV_DIR__`` is replaced with the absolute path of the environment
206 directory.
207
208 * ``__VENV_NAME__`` is replaced with the environment name (final path
209 segment of environment directory).
210
Vinay Sajipdff9e252013-10-02 11:36:16 +0100211 * ``__VENV_PROMPT__`` is replaced with the prompt (the environment
212 name surrounded by parentheses and with a following space)
213
Georg Brandldbab58f2012-06-24 16:37:59 +0200214 * ``__VENV_BIN_NAME__`` is replaced with the name of the bin directory
215 (either ``bin`` or ``Scripts``).
216
217 * ``__VENV_PYTHON__`` is replaced with the absolute path of the
218 environment's executable.
219
Vinay Sajip577d4ff2013-07-12 21:52:51 +0100220 The directories are allowed to exist (for when an existing environment
221 is being upgraded).
Georg Brandldbab58f2012-06-24 16:37:59 +0200222
223There is also a module-level convenience function:
224
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000225.. function:: create(env_dir, system_site_packages=False, clear=False, \
226 symlinks=False, with_pip=False)
Georg Brandldbab58f2012-06-24 16:37:59 +0200227
228 Create an :class:`EnvBuilder` with the given keyword arguments, and call its
229 :meth:`~EnvBuilder.create` method with the *env_dir* argument.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000230
Nick Coghlan8fbdb092013-11-23 00:30:34 +1000231 .. versionchanged:: 3.4
232 Added the ``with_pip`` parameter
233
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000234An example of extending ``EnvBuilder``
235--------------------------------------
236
237The following script shows how to extend :class:`EnvBuilder` by implementing a
Brett Cannon15552c32016-07-08 10:46:21 -0700238subclass which installs setuptools and pip into a created virtual environment::
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000239
240 import os
241 import os.path
242 from subprocess import Popen, PIPE
243 import sys
244 from threading import Thread
245 from urllib.parse import urlparse
246 from urllib.request import urlretrieve
247 import venv
248
Vinay Sajip3c557f22013-07-12 20:54:25 +0100249 class ExtendedEnvBuilder(venv.EnvBuilder):
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000250 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100251 This builder installs setuptools and pip so that you can pip or
Brett Cannon15552c32016-07-08 10:46:21 -0700252 easy_install other packages into the created virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000253
Vinay Sajip3c557f22013-07-12 20:54:25 +0100254 :param nodist: If True, setuptools and pip are not installed into the
Brett Cannon15552c32016-07-08 10:46:21 -0700255 created virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000256 :param nopip: If True, pip is not installed into the created
Brett Cannon15552c32016-07-08 10:46:21 -0700257 virtual environment.
Vinay Sajip3c557f22013-07-12 20:54:25 +0100258 :param progress: If setuptools or pip are installed, the progress of the
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000259 installation can be monitored by passing a progress
260 callable. If specified, it is called with two
261 arguments: a string indicating some progress, and a
262 context indicating where the string is coming from.
263 The context argument can have one of three values:
264 'main', indicating that it is called from virtualize()
265 itself, and 'stdout' and 'stderr', which are obtained
266 by reading lines from the output streams of a subprocess
267 which is used to install the app.
268
269 If a callable is not specified, default progress
270 information is output to sys.stderr.
271 """
272
273 def __init__(self, *args, **kwargs):
274 self.nodist = kwargs.pop('nodist', False)
275 self.nopip = kwargs.pop('nopip', False)
276 self.progress = kwargs.pop('progress', None)
277 self.verbose = kwargs.pop('verbose', False)
278 super().__init__(*args, **kwargs)
279
280 def post_setup(self, context):
281 """
282 Set up any packages which need to be pre-installed into the
Brett Cannon15552c32016-07-08 10:46:21 -0700283 virtual environment being created.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000284
Brett Cannon15552c32016-07-08 10:46:21 -0700285 :param context: The information for the virtual environment
286 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000287 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100288 os.environ['VIRTUAL_ENV'] = context.env_dir
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000289 if not self.nodist:
Vinay Sajip3c557f22013-07-12 20:54:25 +0100290 self.install_setuptools(context)
291 # Can't install pip without setuptools
292 if not self.nopip and not self.nodist:
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000293 self.install_pip(context)
294
295 def reader(self, stream, context):
296 """
297 Read lines from a subprocess' output stream and either pass to a progress
298 callable (if specified) or write progress information to sys.stderr.
299 """
300 progress = self.progress
301 while True:
302 s = stream.readline()
303 if not s:
304 break
305 if progress is not None:
306 progress(s, context)
307 else:
308 if not self.verbose:
309 sys.stderr.write('.')
310 else:
311 sys.stderr.write(s.decode('utf-8'))
312 sys.stderr.flush()
Vinay Sajipad6bb032013-07-12 21:44:35 +0100313 stream.close()
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000314
315 def install_script(self, context, name, url):
316 _, _, path, _, _, _ = urlparse(url)
317 fn = os.path.split(path)[-1]
318 binpath = context.bin_path
319 distpath = os.path.join(binpath, fn)
Brett Cannon15552c32016-07-08 10:46:21 -0700320 # Download script into the virtual environment's binaries folder
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000321 urlretrieve(url, distpath)
322 progress = self.progress
Vinay Sajip3c557f22013-07-12 20:54:25 +0100323 if self.verbose:
324 term = '\n'
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000325 else:
Vinay Sajip3c557f22013-07-12 20:54:25 +0100326 term = ''
327 if progress is not None:
328 progress('Installing %s ...%s' % (name, term), 'main')
329 else:
330 sys.stderr.write('Installing %s ...%s' % (name, term))
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000331 sys.stderr.flush()
Brett Cannon15552c32016-07-08 10:46:21 -0700332 # Install in the virtual environment
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000333 args = [context.env_exe, fn]
334 p = Popen(args, stdout=PIPE, stderr=PIPE, cwd=binpath)
335 t1 = Thread(target=self.reader, args=(p.stdout, 'stdout'))
336 t1.start()
337 t2 = Thread(target=self.reader, args=(p.stderr, 'stderr'))
338 t2.start()
339 p.wait()
340 t1.join()
341 t2.join()
342 if progress is not None:
343 progress('done.', 'main')
344 else:
345 sys.stderr.write('done.\n')
346 # Clean up - no longer needed
347 os.unlink(distpath)
348
Vinay Sajip3c557f22013-07-12 20:54:25 +0100349 def install_setuptools(self, context):
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000350 """
Brett Cannon15552c32016-07-08 10:46:21 -0700351 Install setuptools in the virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000352
Brett Cannon15552c32016-07-08 10:46:21 -0700353 :param context: The information for the virtual environment
354 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000355 """
Vinay Sajip3c557f22013-07-12 20:54:25 +0100356 url = 'https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py'
357 self.install_script(context, 'setuptools', url)
358 # clear up the setuptools archive which gets downloaded
359 pred = lambda o: o.startswith('setuptools-') and o.endswith('.tar.gz')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000360 files = filter(pred, os.listdir(context.bin_path))
361 for f in files:
362 f = os.path.join(context.bin_path, f)
363 os.unlink(f)
364
365 def install_pip(self, context):
366 """
Brett Cannon15552c32016-07-08 10:46:21 -0700367 Install pip in the virtual environment.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000368
Brett Cannon15552c32016-07-08 10:46:21 -0700369 :param context: The information for the virtual environment
370 creation request being processed.
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000371 """
372 url = 'https://raw.github.com/pypa/pip/master/contrib/get-pip.py'
373 self.install_script(context, 'pip', url)
374
375 def main(args=None):
376 compatible = True
377 if sys.version_info < (3, 3):
378 compatible = False
379 elif not hasattr(sys, 'base_prefix'):
380 compatible = False
381 if not compatible:
382 raise ValueError('This script is only for use with '
383 'Python 3.3 or later')
384 else:
385 import argparse
386
387 parser = argparse.ArgumentParser(prog=__name__,
388 description='Creates virtual Python '
389 'environments in one or '
390 'more target '
391 'directories.')
392 parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
Brett Cannon15552c32016-07-08 10:46:21 -0700393 help='A directory in which to create the
394 'virtual environment.')
Vinay Sajip3c557f22013-07-12 20:54:25 +0100395 parser.add_argument('--no-setuptools', default=False,
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000396 action='store_true', dest='nodist',
Vinay Sajip3c557f22013-07-12 20:54:25 +0100397 help="Don't install setuptools or pip in the "
398 "virtual environment.")
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000399 parser.add_argument('--no-pip', default=False,
400 action='store_true', dest='nopip',
401 help="Don't install pip in the virtual "
402 "environment.")
403 parser.add_argument('--system-site-packages', default=False,
404 action='store_true', dest='system_site',
405 help='Give the virtual environment access to the '
406 'system site-packages dir.')
407 if os.name == 'nt':
408 use_symlinks = False
409 else:
410 use_symlinks = True
411 parser.add_argument('--symlinks', default=use_symlinks,
412 action='store_true', dest='symlinks',
413 help='Try to use symlinks rather than copies, '
414 'when symlinks are not the default for '
415 'the platform.')
416 parser.add_argument('--clear', default=False, action='store_true',
417 dest='clear', help='Delete the contents of the '
Brett Cannon15552c32016-07-08 10:46:21 -0700418 'virtual environment '
419 'directory if it already '
420 'exists, before virtual '
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000421 'environment creation.')
422 parser.add_argument('--upgrade', default=False, action='store_true',
Brett Cannon15552c32016-07-08 10:46:21 -0700423 dest='upgrade', help='Upgrade the virtual '
424 'environment directory to '
425 'use this version of '
426 'Python, assuming Python '
427 'has been upgraded '
428 'in-place.')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000429 parser.add_argument('--verbose', default=False, action='store_true',
430 dest='verbose', help='Display the output '
431 'from the scripts which '
Vinay Sajip3c557f22013-07-12 20:54:25 +0100432 'install setuptools and pip.')
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000433 options = parser.parse_args(args)
434 if options.upgrade and options.clear:
435 raise ValueError('you cannot supply --upgrade and --clear together.')
Vinay Sajip3c557f22013-07-12 20:54:25 +0100436 builder = ExtendedEnvBuilder(system_site_packages=options.system_site,
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000437 clear=options.clear,
438 symlinks=options.symlinks,
439 upgrade=options.upgrade,
440 nodist=options.nodist,
441 nopip=options.nopip,
442 verbose=options.verbose)
443 for d in options.dirs:
444 builder.create(d)
445
446 if __name__ == '__main__':
447 rc = 1
448 try:
449 main()
450 rc = 0
451 except Exception as e:
452 print('Error: %s' % e, file=sys.stderr)
453 sys.exit(rc)
454
Vinay Sajip3c557f22013-07-12 20:54:25 +0100455
Vinay Sajip2b4fcfb2013-01-30 13:44:00 +0000456This script is also available for download `online
Sanyam Khurana338cd832018-01-20 05:55:37 +0530457<https://gist.github.com/vsajip/4673395>`_.