.. data:: base_exec_prefix
Set during Python startup, before ``site.py`` is run, to the same value as
- :data:`exec_prefix`. If not running in a virtual environment, the values
- will stay the same; if ``site.py`` finds that a virtual environment is in
- use, the values of :data:`prefix` and :data:`exec_prefix` will be changed to
- point to the virtual environment, whereas :data:`base_prefix` and
+ :data:`exec_prefix`. If not running in a
+ :ref:`virtual environment <venv-def>`, the values will stay the same; if
+ ``site.py`` finds that a virtual environment is in use, the values of
+ :data:`prefix` and :data:`exec_prefix` will be changed to point to the
+ virtual environment, whereas :data:`base_prefix` and
:data:`base_exec_prefix` will remain pointing to the base Python
installation (the one which the virtual environment was created from).
.. data:: base_prefix
Set during Python startup, before ``site.py`` is run, to the same value as
- :data:`prefix`. If not running in a virtual environment, the values
+ :data:`prefix`. If not running in a :ref:`virtual environment <venv-def>`, the values
will stay the same; if ``site.py`` finds that a virtual environment is in
use, the values of :data:`prefix` and :data:`exec_prefix` will be changed to
point to the virtual environment, whereas :data:`base_prefix` and
installed in :file:`{exec_prefix}/lib/python{X.Y}/lib-dynload`, where *X.Y*
is the version number of Python, for example ``3.2``.
- .. note:: If a virtual environment is in effect, this value will be changed
- in ``site.py`` to point to the virtual environment. The value for the
- Python installation will still be available, via :data:`base_exec_prefix`.
+ .. note:: If a :ref:`virtual environment <venv-def>` is in effect, this
+ value will be changed in ``site.py`` to point to the virtual environment.
+ The value for the Python installation will still be available, via
+ :data:`base_exec_prefix`.
.. data:: executable
stored in :file:`{prefix}/include/python{X.Y}`, where *X.Y* is the version
number of Python, for example ``3.2``.
- .. note:: If a virtual environment is in effect, this value will be changed
- in ``site.py`` to point to the virtual environment. The value for the
- Python installation will still be available, via :data:`base_prefix`.
+ .. note:: If a :ref:`virtual environment <venv-def>` is in effect, this
+ value will be changed in ``site.py`` to point to the virtual
+ environment. The value for the Python installation will still be
+ available, via :data:`base_prefix`.
.. data:: ps1
whereas on Windows, you might do::
- c:\> <venv>/Scripts/activate
+ C:\> <venv>/Scripts/activate
if you are using the ``cmd.exe`` shell, or perhaps::
``deactivate.bat`` and ``Deactivate.ps1`` which are installed when the venv is
created.
+.. _venv-def:
+
.. note:: A virtual environment (also called a ``venv``) is a Python
environment such that the Python interpreter, libraries and scripts
installed into it are isolated from those installed in other virtual
pyvenv - Creating virtual environments
--------------------------------------
-Creation of virtual environments is done by executing the ``pyvenv``
-script::
+Creation of :ref:`virtual environments <venv-def>` is done by executing the
+``pyvenv`` script::
pyvenv /path/to/new/virtual/environment
whereas on Windows, you might do::
- c:\> <venv>/Scripts/activate
+ C:\> <venv>/Scripts/activate
if you are using the ``cmd.exe`` shell, or perhaps::
``deactivate.bat`` and ``Deactivate.ps1`` which are installed when the venv is
created.
-.. note:: A virtual environment (also called a ``venv``) is a Python
- environment such that the Python interpreter, libraries and scripts
- installed into it are isolated from those installed in other virtual
- environments, and (by default) any libraries installed in a "system" Python,
- i.e. one which is installed as part of your operating system.
-
- A venv is a directory tree which contains Python executable files and
- other files which indicate that it is a venv.
-
- Common installation tools such as ``distribute`` and ``pip`` work as
- expected with venvs - i.e. when a venv is active, they install Python
- packages into the venv without needing to be told to do so explicitly.
-
- When a venv is active (i.e. the venv's Python interpreter is running), the
- attributes :attr:`sys.prefix` and :attr:`sys.exec_prefix` point to the base
- directory of the venv, whereas :attr:`sys.base_prefix` and
- :attr:`sys.base_exec_prefix` point to the non-venv Python installation
- which was used to create the venv. If a venv is not active, then
- :attr:`sys.prefix` is the same as :attr:`sys.base_prefix` and
- :attr:`sys.exec_prefix` is the same as :attr:`sys.base_exec_prefix` (they
- all point to a non-venv Python installation).
-