Skip to content

Commit 195930f

Browse files
committed
Show how to use a virtual environment without activation
1 parent 5b31c28 commit 195930f

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

‎source/guides/installing-using-pip-and-virtual-environments.rst‎

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@ can just create this in your project and call it ``.venv``.
7373
Activate a virtual environment
7474
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7575

76-
Before you can start installing or using packages in your virtual environment you'll
77-
need to ``activate`` it. Activating a virtual environment will put the
78-
virtual environment-specific ``python`` and ``pip`` executables into your
79-
shell's ``PATH``.
76+
Activating a virtual environment puts its executable directory first on
77+
your current shell's ``PATH``. This lets commands such as ``python`` and
78+
``pip`` select the copies in the virtual environment.
8079

8180
.. tab:: Unix/macOS
8281

@@ -121,9 +120,24 @@ filepath that includes the ``.venv`` directory, by ending with the following:
121120
.venv\Scripts\python
122121
123122
124-
While a virtual environment is activated, pip will install packages into that
125-
specific environment. This enables you to import and use packages in your
126-
Python application.
123+
Activation is optional. You can run the virtual environment's Python
124+
directly, including when invoking pip:
125+
126+
.. tab:: Unix/macOS
127+
128+
.. code-block:: bash
129+
130+
.venv/bin/python -m pip --version
131+
132+
.. tab:: Windows
133+
134+
.. code-block:: bat
135+
136+
.venv\Scripts\python.exe -m pip --version
137+
138+
Use the same executable path with ``-m pip install`` to install packages
139+
into that environment, or with a script path to run a Python program there.
140+
The rest of this guide assumes you activated the environment.
127141

128142

129143
Deactivate a virtual environment

0 commit comments

Comments
 (0)