You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To use the virtual environment's Python executable directly, run
246
+
``venv/bin/python``; to use its pip executable, ``venv/bin/pip``.
255
247
256
-
2. To begin using the virtual environment, it needs to be activated:
248
+
Alternatively, you can "activate"
249
+
the environment so you can just type ``python`` or ``pip`` and it will automatically use the
250
+
executables in the virtual environment (in this case, at ``venv/bin``).
257
251
258
252
.. code-block:: console
259
253
260
254
$ source venv/bin/activate
261
255
262
-
The name of the current virtual environment will now appear on the left of
256
+
Now, the name of the current virtual environment will appear on the left of
263
257
the prompt (e.g. ``(venv)Your-Computer:project_folder UserName$``) to let you know
264
258
that it's active. From now on, any package that you install using pip will be
265
259
placed in the ``venv`` folder, isolated from the global Python installation.
266
260
267
-
For Windows, the same command mentioned in step 1 can be used to create a virtual environment. However, activating the environment requires a slightly different command.
261
+
For Windows, the same command mentioned in step 1 can be used to create a virtual environment.
262
+
However, activating the environment requires a slightly different command.
268
263
269
264
Assuming that you are in your project directory:
270
265
@@ -286,25 +281,26 @@ Install packages using the ``pip`` command:
286
281
$ deactivate
287
282
288
283
This puts you back to the system's default Python interpreter with all its
289
-
installed libraries.
284
+
installed libraries. This is not necessary if you invoked the executables directly.
290
285
291
286
To delete a virtual environment, just delete its folder. (In this case,
292
287
it would be ``rm -rf venv``.)
293
288
294
289
After a while, though, you might end up with a lot of virtual environments
295
-
littered across your system, and it's possible you'll forget their names or
296
-
where they were placed.
290
+
littered across your system. It's possible you'll forget their names or
291
+
where they were placed, so try to follow a convention across your projects.
297
292
298
293
.. note::
299
-
Python has included venv module from version 3.3. For more details: `venv <https://docs.python.org/3/library/venv.html>`_.
294
+
The ``venv`` module is part of Python's standard library in Python3.3+.
295
+
Older versions of Python can use the
296
+
3rd party package `virtualenv <https://pypi.org/project/virtualenv/>`_.
300
297
301
298
Other Notes
302
299
-----------
303
300
304
-
Running ``virtualenv`` with the option ``--no-site-packages`` will not
301
+
Running ``python -m venv`` with the option ``--no-site-packages`` will not
305
302
include the packages that are installed globally. This can be useful
306
303
for keeping the package list clean in case it needs to be accessed later.
307
-
[This is the default behavior for ``virtualenv`` 1.7 and later.]
308
304
309
305
In order to keep your environment consistent, it's a good idea to "freeze"
310
306
the current state of the environment packages. To do this, run:
@@ -330,103 +326,6 @@ and across developers.
330
326
Lastly, remember to exclude the virtual environment folder from source
331
327
control by adding it to the ignore list (see :ref:`Version Control Ignores<version_control_ignores>`).
0 commit comments