File: virtualenv.rst

package info (click to toggle)
python-click 8.2.0%2B0.really.8.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 1,456 kB
  • sloc: python: 11,531; makefile: 28; sh: 11
file content (54 lines) | stat: -rw-r--r-- 1,292 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
.. _virtualenv-heading:

Virtualenv
=========================

Why Use Virtualenv?
-------------------------

You should use `Virtualenv <https://virtualenv.pypa.io/en/latest/>`_ because:

*   It allows you to install multiple versions of the same dependency.

*   If you have an operating system version of Python, it prevents you from changing its dependencies and potentially messing up your os.

How to Use Virtualenv
-----------------------------

Create your project folder, then a virtualenv within it::

    $ mkdir myproject
    $ cd myproject
    $ python3 -m venv .venv

Now, whenever you want to work on a project, you only have to activate the
corresponding environment.

.. tabs::

    .. group-tab:: OSX/Linux

        .. code-block:: text

            $ . .venv/bin/activate
            (venv) $

    .. group-tab:: Windows

        .. code-block:: text

            > .venv\scripts\activate
            (venv) >


You are now using your virtualenv (notice how the prompt of your shell has changed to show the active environment).

To install packages in the virtual environment::

    $ pip install click

And if you want to stop using the virtualenv, use the following command::

    $ deactivate

After doing this, the prompt of your shell should be as familiar as before.