Installing and using the virtualenv tool

virtualenv is a tool that creates isolated Python environments.

These isolated environments can have their own separate versions of

Python packages, which allows you to isolate one project's

dependencies from the dependencies of other projects. It is

recommended that you always use a per-project virtual environment when

developing locally with Python.

Install virtualenv globally.

To install pip with Python 2 or Python 3, use pip install --upgrade virtualenv.

After you install virtualenv, you can create a virtual environment in

your project. virtualenv creates a virtual copy of the entire Python

installation in the env folder.

Use the --python flag to tell virtualenv which Python version to use:

cd your-project

virtualenv --python python3 env

After the copy is created, set your shell to use the virtualenv paths

for Python by activating the virtual environment as follows.

source env/bin/activate

Now you can install packages without affecting other projects or your

global Python installation:

If you want to stop using the virtual environment and go back to your

global Python, you can deactivate it:



Popular posts from this blog