Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate out virtualenv to its own sections #2551

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ usage patterns.

why
quickstart
virtualenv
setuptools
parameters
options
Expand Down
61 changes: 4 additions & 57 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,13 @@ Quickstart

.. currentmodule:: click

You can get the library directly from PyPI::
Install
----------------------
Install from PyPI::

pip install click

The installation into a :ref:`virtualenv` is heavily recommended.

.. _virtualenv:

virtualenv
----------

Virtualenv is probably what you want to use for developing Click
applications.

What problem does virtualenv solve? Chances are that you want to use it
for other projects besides your Click script. But the more projects you
have, the more likely it is that you will be working with different
versions of Python itself, or at least different versions of Python
libraries. Let's face it: quite often libraries break backwards
compatibility, and it's unlikely that any serious application will have
zero dependencies. So what do you do if two or more of your projects have
conflicting dependencies?

Virtualenv to the rescue! Virtualenv enables multiple side-by-side
installations of Python, one for each project. It doesn't actually
install separate copies of Python, but it does provide a clever way to
keep different project environments isolated.

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. On OS X and Linux, do the following::

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

If you are a Windows user, the following command is for you::

> .venv\scripts\activate
(venv) >

Either way, you should now be using your virtualenv (notice how the prompt of
your shell has changed to show the active environment).

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.

Now, let's move on. Enter the following command to get Click activated in your
virtualenv::

$ pip install click

A few seconds later and you are good to go.
Installing into a virtual environment is highly recommended. We suggest :ref:`virtualenv-heading`.

Screencast and Examples
-----------------------
Expand Down
54 changes: 54 additions & 0 deletions docs/virtualenv.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,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::
Rowlando13 marked this conversation as resolved.
Show resolved Hide resolved

$ 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.