# Managing Python packages the right way and not suffer with "Pip environment pollution".

# Managing Python packages the right way

"Pip environment pollution/Python environment pollution" refers to the situation where multiple versions of the same package are installed in different environments, such as in different virtual environments or in the global environment, and this can cause conflicts and issues when running the code.

To avoid pip environment pollution, it is recommended to use a virtual environment for each project and install the required packages in the virtual environment. This will ensure that the packages are isolated from the global environment and other virtual environments, so there will be no conflicts or issues caused by having multiple versions of the same package installed.

To create a virtual environment and install packages in it using pip, you can use the following steps:

1.  Install the `virtualenv` package using the following command:
    

```python
pip install virtualenv
```

2.  Create a new virtual environment for your project using the following command:
    

```python
virtualenv /path/to/my/env
```

3.  Activate the virtual environment using the following command:
    

```python
source /path/to/my/env/bin/activate
```

4.  Install the required packages in the virtual environment using the following command:
    

```python
pip install <package-name>
```

5.  When you are done working on the project and want to deactivate the virtual environment, use the following command:
    

```python
deactivate
```

By using a virtual environment for each project, you can avoid pip environment pollution and ensure that your projects are isolated from each other and from the global environment. This can help prevent conflicts and issues caused by having multiple versions of the same package installed.
