From 195930ff49e990636d7d7bec0a0dbe7f90731e47 Mon Sep 17 00:00:00 2001 From: CloudGPU <129925370+cloudgpuapp@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:15:02 +0800 Subject: [PATCH] Show how to use a virtual environment without activation --- ...ing-using-pip-and-virtual-environments.rst | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/source/guides/installing-using-pip-and-virtual-environments.rst b/source/guides/installing-using-pip-and-virtual-environments.rst index 9d0cc61965..51c37b66e1 100644 --- a/source/guides/installing-using-pip-and-virtual-environments.rst +++ b/source/guides/installing-using-pip-and-virtual-environments.rst @@ -73,10 +73,9 @@ can just create this in your project and call it ``.venv``. Activate a virtual environment ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Before you can start installing or using packages in your virtual environment you'll -need to ``activate`` it. Activating a virtual environment will put the -virtual environment-specific ``python`` and ``pip`` executables into your -shell's ``PATH``. +Activating a virtual environment puts its executable directory first on +your current shell's ``PATH``. This lets commands such as ``python`` and +``pip`` select the copies in the virtual environment. .. tab:: Unix/macOS @@ -121,9 +120,24 @@ filepath that includes the ``.venv`` directory, by ending with the following: .venv\Scripts\python -While a virtual environment is activated, pip will install packages into that -specific environment. This enables you to import and use packages in your -Python application. +Activation is optional. You can run the virtual environment's Python +directly, including when invoking pip: + +.. tab:: Unix/macOS + + .. code-block:: bash + + .venv/bin/python -m pip --version + +.. tab:: Windows + + .. code-block:: bat + + .venv\Scripts\python.exe -m pip --version + +Use the same executable path with ``-m pip install`` to install packages +into that environment, or with a script path to run a Python program there. +The rest of this guide assumes you activated the environment. Deactivate a virtual environment