Files
palemoon27/python/virtualenv/docs/userguide.rst
roytam1 9194d38508 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 711670: Setup the Mac Application Delegate earlier to respond to URLs clicked in external applications when updates are pending. r=mstange (2471469680)
- Bug 1252889: On Windows use a 10 second pause instead of trying to invoke the JIT debugger with MOZ_DEBUG_CHILD_PROCESS. r=jimm (228cd75e4d)
- Bug 1253850: On Windows change MOZ_DEBUG_CHILD_PROCESS back to JIT and add MOZ_DEBUG_CHILD_PAUSE for a 10 second pause. r=mchang (83cdaec0a7)
- Bug 1259809 - Make CrashReporter::InitChildProcessTmpDir conditional on MOZ_CRASHREPORTER. r=aklotz (19672176dd)
- Bug 1176703 - attempt to fix define issues with some compilers/envs, rs=me, CLOSED TREE, bustage (8e6f3a6b94)
- Bug 1266292 - Remove unnecessary compiler checks for MSVS 2010 in gfx/2d/. r=bas (9c3acd9f5d)
- Bug 1195788 - Set arithmetic composite clamp to true for D2D filter node. r=bas (5ba4191512)
- Bug 1248223 - verify that stroke widths are finite for Skia. r=jmuizelaar (1f676f5c24)
- Bug 1241918 - remove workarounds for zero-length dash intervals in HelpersSkia.h, r=jrmuizel (ce0665ab77)
- crashreporter includes (c64d834706)
- Add a driver crash guard to D3D11 DXVA. (bug 1253666, r=mattwoodrow) (8589eef61b)
- Bug 1189918 - Theme overrides should work in safe mode for comm-central applications too. r=bsmedberg (535486b4c0)
- Disable the WebGL crash guard on Android. (bug 1256371, r=snorp) a=merge (855cc66aef)
- Bug 1265273 - Add two missing get_PBrowserParent() null checks. r=jimm. (b5f9ac0967)
- Bug 1261599 - null check SendPBrowserConstructor return in ContentParent to avoid crashes on content process shutdown. r=smaug (28e2ad71b5)
- Bug 1249733 - Sign talos harness and test extensions, r=jmaher (55d030ea53)
- Bug 1253382 - Force the initial browser remoteness only after the browser's onLoad has fired. r=jmaher (40e7723e3a)
- Bug 1253994 - Make profile collection more robust (r=mconley) (a3b1392011)
- Fix D3D11VideoCrashGuard missing a switch case in ContentParent. (bug 1263725, r=mattwoodrow) (07a5b63633)
- Bug 1216371 - Load default theme from XPI in safe mode. r=bsmedberg (596bc54a13)
- Bug 1162965 - Use /dev/shm instead of /tmp for sandbox chroot if possible. r=kang (4fa3c77756)
- Bug 1264226: Don't use '_COARSE' Posix clocks if not defined, r=jld (a173b195eb)
- Bug 1259273 - Add sys_unlink to seccomp-bpf whitelist. r=jld (72ca2626f6)
- Bug 1259283 - Add sys_fchown to seccomp whitelist. r=jld (628f3cd627)
- Bug 1253194: Suppress -Wimplicit-fallthrough clang warning for intentional fallthrough in icu_utf.cc (which is imported code). r=bobowen (a503963ff2)
- Bug 1257031 - Return more informative error code when encountering invalid integers rather than SEC_ERROR_BAD_DER. r=keeler (7f4955614a)
- Bug 1153446 - Replace instances of double spacing with single spacing in nsserrors.properties. r=dkeeler (166f0bd1c4)
- Bug 1259551 - Upgrade vendored virtualenv to 15.0.1; r=ted (81dcf300ff)
- Bug 1258574 - Allow JARReader to read data already in memory; r=glandium (87fc89d6fc)
- Bug 1256530 - Fix compiler warnings about casting to larger size. r=hsivonen (53020d1543)
- Bug 1251235 - changed from naked pointers to UniquePtr to prevent resource leak. r=froydnj (953040a377)
- Bug 1264887: |nsWifiScannerDBus|: Hold DBusConnection reference in |RefPtr|, r=josh (3d8b9b3f52)
- Bug 1212056 - Add virtual dtor to WindowsWifiScannerInterface. r=jdm (ce00cf01e9)
- code style (d7fea73856)
- Bug 1222170 - fix initialization order in ScopedWLANObject; r=jimm (b515ea0273)
- Bug 1204919 - Build osx_corewlan.mm with -Wno-error=objc-method-access to avoid bustage on some machines in warnings-on-errors builds. r=glandium. (f88b02868d)
- Bug 1204277 - Disallow warnings in six more directories. r=glandium. (7e249cf4ab)
- Bug 1248761 - Destroy VRHMDInfo objects on the compositor thread r=daoshengmu (ccf6af1fec)
- Bug 1260530 - Add support for Oculus 1.3 runtime r=daoshengmu (f7ed5abb4f)
- Bug 1242005 - Disable C4359 to allow compilation on VS2015; r=kip (71db7148f4)
- Bug 1176158 - "Remove unused lang atoms (ko-xxx and x-symbol)" r=vladimir (25e46d1150)
- Bug 1176158 - Part 2. Remove unused ko_xxx and x_symbols from gfxGDIFontList. r=jdaggett (9b213333e0)
- Bug 1262304 - Add a pref to dump display lists for the content process. r=BenWa (c0a4e56542)
- Bug 1180942 - Use cairo's image backend for drawing on linux. r=jrmuizel (83deed801b)
- Bug 1254400 - Handle device reset for d3d9. r=dvander (170aaeb272)
- Bug 1254400 - Make access to d3d9 device manager thread-safe. r=dvander (a6112d8b84)
- Bug 1256547: When the DWM is disabled don't force presentation. r=milan (0fe31bfc50)
- Bug 1229988 - verify that reference draw target is created after device reset and log failure in gfxWindowsPlatform::UpdateRenderMode. r=milan (32084a6688)
- Bug 1250669. Don't init dwrite fonts if content device creation fails. r=dvander (4a55599c8b)
- Include vendor and device ids in content process DXGI adapter matching. (bug 1228905, r=jrmuizel) (c9403d3798)
- Bug 1233576. Ensure vsync timestamps are monotonic on Windows 10. r=kats (d075fb7230)
- Bug 1249036 Check that DWMFlush executes correctly. r=kats (f460b09853)
- Bug 1259248. Follow up to fix static analysis bustage (ab462300ff)
- Bug 1259248. Add a comment about mfbt/Range.h (a78f7c2110)
- Bug 1262681 - Draw target also has to be valid for us to demand a snapshot. r=bas (c4c0bfcaca)
- Bug 1258313 - Allow snapping of 'pseudo' 3d transforms. r=jrmuizel (fc85ac9147)
- Bug 1241060 - Skip non-2d sibling layers when calculating plugin window clipping under e10s. r=mstange (fc6836ab11)
- Bug 1257288 - Have APZ hit testing respect scroll clips. r=kats (5f8db91909)
- Bug 1255961 - Avoid zeroing out shmems (r=dvander) (cc0e856f83)
- Bug 1251523 - Remove TextureFlags::DEALLOCATE_CLIENT from AndroidSurfaceTextureData r=nical (406a27e229)
- Regenerate SyncObjects on device resets. (bug 1255711, r=bas) (8a83c23cdf)
- Bug 1240659 - Add GonkNativeHandle::CreateDupNhObj() r=nical (3da777655e)
- Bug 1238602 - Update ParamTraits<GonkNativeHandle>::Read() r=nical (969f8177fd)
- Bug 1248923 - Store result in Update ParamTraits<GonkNativeHandle>::Read() r=nical (0052a996a0)
- Bug 1219794 - Show the bookmark popup for new bookmarks and autoclose if no interaction. r=mak (19cca3c48f)
- minor removal of preproc (521c8493a2)
2024-07-19 22:23:30 +08:00

259 lines
10 KiB
ReStructuredText

User Guide
==========
Usage
-----
Virtualenv has one basic command::
$ virtualenv ENV
Where ``ENV`` is a directory to place the new virtual environment. It has
a number of usual effects (modifiable by many :ref:`options`):
- :file:`ENV/lib/` and :file:`ENV/include/` are created, containing supporting
library files for a new virtualenv python. Packages installed in this
environment will live under :file:`ENV/lib/pythonX.X/site-packages/`.
- :file:`ENV/bin` is created, where executables live - noticeably a new
:command:`python`. Thus running a script with ``#! /path/to/ENV/bin/python``
would run that script under this virtualenv's python.
- The crucial packages pip_ and setuptools_ are installed, which allow other
packages to be easily installed to the environment. This associated pip
can be run from :file:`ENV/bin/pip`.
The python in your new virtualenv is effectively isolated from the python that
was used to create it.
.. _pip: https://pypi.python.org/pypi/pip
.. _setuptools: https://pypi.python.org/pypi/setuptools
.. _activate:
activate script
~~~~~~~~~~~~~~~
In a newly created virtualenv there will also be a :command:`activate` shell
script. For Windows systems, activation scripts are provided for
the Command Prompt and Powershell.
On Posix systems, this resides in :file:`/ENV/bin/`, so you can run::
$ source bin/activate
For some shells (e.g. the original Bourne Shell) you may need to use the
:command:`.` command, when :command:`source` does not exist. There are also
separate activate files for some other shells, like csh and fish.
:file:`bin/activate` should work for bash/zsh/dash.
This will change your ``$PATH`` so its first entry is the virtualenv's
``bin/`` directory. (You have to use ``source`` because it changes your
shell environment in-place.) This is all it does; it's purely a
convenience. If you directly run a script or the python interpreter
from the virtualenv's ``bin/`` directory (e.g. ``path/to/ENV/bin/pip``
or ``/path/to/ENV/bin/python-script.py``) there's no need for
activation.
The ``activate`` script will also modify your shell prompt to indicate
which environment is currently active. To disable this behaviour, see
:envvar:`VIRTUAL_ENV_DISABLE_PROMPT`.
To undo these changes to your path (and prompt), just run::
$ deactivate
On Windows, the equivalent `activate` script is in the ``Scripts`` folder::
> \path\to\env\Scripts\activate
And type ``deactivate`` to undo the changes.
Based on your active shell (CMD.exe or Powershell.exe), Windows will use
either activate.bat or activate.ps1 (as appropriate) to activate the
virtual environment. If using Powershell, see the notes about code signing
below.
.. note::
If using Powershell, the ``activate`` script is subject to the
`execution policies`_ on the system. By default on Windows 7, the system's
excution policy is set to ``Restricted``, meaning no scripts like the
``activate`` script are allowed to be executed. But that can't stop us
from changing that slightly to allow it to be executed.
In order to use the script, you can relax your system's execution
policy to ``AllSigned``, meaning all scripts on the system must be
digitally signed to be executed. Since the virtualenv activation
script is signed by one of the authors (Jannis Leidel) this level of
the execution policy suffices. As an administrator run::
PS C:\> Set-ExecutionPolicy AllSigned
Then you'll be asked to trust the signer, when executing the script.
You will be prompted with the following::
PS C:\> virtualenv .\foo
New python executable in C:\foo\Scripts\python.exe
Installing setuptools................done.
Installing pip...................done.
PS C:\> .\foo\scripts\activate
Do you want to run software from this untrusted publisher?
File C:\foo\scripts\activate.ps1 is published by E=jannis@leidel.info,
CN=Jannis Leidel, L=Berlin, S=Berlin, C=DE, Description=581796-Gh7xfJxkxQSIO4E0
and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run [D] Do not run [R] Run once [A] Always run [?] Help
(default is "D"):A
(foo) PS C:\>
If you select ``[A] Always Run``, the certificate will be added to the
Trusted Publishers of your user account, and will be trusted in this
user's context henceforth. If you select ``[R] Run Once``, the script will
be run, but you will be prometed on a subsequent invocation. Advanced users
can add the signer's certificate to the Trusted Publishers of the Computer
account to apply to all users (though this technique is out of scope of this
document).
Alternatively, you may relax the system execution policy to allow running
of local scripts without verifying the code signature using the following::
PS C:\> Set-ExecutionPolicy RemoteSigned
Since the ``activate.ps1`` script is generated locally for each virtualenv,
it is not considered a remote script and can then be executed.
.. _`execution policies`: http://technet.microsoft.com/en-us/library/dd347641.aspx
Removing an Environment
~~~~~~~~~~~~~~~~~~~~~~~
Removing a virtual environment is simply done by deactivating it and deleting the
environment folder with all its contents::
(ENV)$ deactivate
$ rm -r /path/to/ENV
The :option:`--system-site-packages` Option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If you build with ``virtualenv --system-site-packages ENV``, your virtual
environment will inherit packages from ``/usr/lib/python2.7/site-packages``
(or wherever your global site-packages directory is).
This can be used if you have control over the global site-packages directory,
and you want to depend on the packages there. If you want isolation from the
global system, do not use this flag.
Windows Notes
~~~~~~~~~~~~~
Some paths within the virtualenv are slightly different on Windows: scripts and
executables on Windows go in ``ENV\Scripts\`` instead of ``ENV/bin/`` and
libraries go in ``ENV\Lib\`` rather than ``ENV/lib/``.
To create a virtualenv under a path with spaces in it on Windows, you'll need
the `win32api <http://sourceforge.net/projects/pywin32/>`_ library installed.
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. A script is available to correct the path. You
can setup the environment like::
activate_this = '/path/to/env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
This will change ``sys.path`` and even change ``sys.prefix``, but also allow
you to use an existing interpreter. Items in your environment will show up
first on ``sys.path``, before global items. However, global items will
always be accessible (as if the :option:`--system-site-packages` flag had been
used in creating the environment, whether it was or not). Also, this cannot undo
the activation of other environments, or modules that have been imported.
You shouldn't try to, for instance, activate an environment before a web
request; you should activate *one* environment as early as possible, and not
do it again in that process.
Making Environments Relocatable
-------------------------------
**Note:** this option is somewhat experimental, and there are probably
caveats that have not yet been identified.
.. warning::
The ``--relocatable`` option currently has a number of issues,
and is not guaranteed to work in all circumstances. It is possible
that the option will be deprecated in a future version of ``virtualenv``.
Normally environments are tied to a specific path. That means that
you cannot move an environment around or copy it to another computer.
You can fix up an environment to make it relocatable with the
command::
$ virtualenv --relocatable ENV
This will make some of the files created by setuptools use relative paths,
and will change all the scripts to use ``activate_this.py`` instead of using
the location of the Python interpreter to select the environment.
**Note:** scripts which have been made relocatable will only work if
the virtualenv is activated, specifically the python executable from
the virtualenv must be the first one on the system PATH. Also note that
the activate scripts are not currently made relocatable by
``virtualenv --relocatable``.
**Note:** you must run this after you've installed *any* packages into
the environment. If you make an environment relocatable, then
install a new package, you must run ``virtualenv --relocatable``
again.
Also, this **does not make your packages cross-platform**. You can
move the directory around, but it can only be used on other similar
computers. Some known environmental differences that can cause
incompatibilities: a different version of Python, when one platform
uses UCS2 for its internal unicode representation and another uses
UCS4 (a compile-time option), obvious platform changes like Windows
vs. Linux, or Intel vs. ARM, and if you have libraries that bind to C
libraries on the system, if those C libraries are located somewhere
different (either different versions, or a different filesystem
layout).
If you use this flag to create an environment, currently, the
:option:`--system-site-packages` option will be implied.
The :option:`--extra-search-dir` option
---------------------------------------
This option allows you to provide your own versions of setuptools and/or
pip to use instead of the embedded versions that come with virtualenv.
To use this feature, pass one or more ``--extra-search-dir`` options to
virtualenv like this::
$ virtualenv --extra-search-dir=/path/to/distributions ENV
The ``/path/to/distributions`` path should point to a directory that contains
setuptools and/or pip wheels.
virtualenv will look for wheels in the specified directories, but will use
pip's standard algorithm for selecting the wheel to install, which looks for
the latest compatible wheel.
As well as the extra directories, the search order includes:
#. The ``virtualenv_support`` directory relative to virtualenv.py
#. The directory where virtualenv.py is located.
#. The current directory.