# Newbie trying to understand pip and virtual environment

**URL:** <https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303>\
**Category:** Python Help\
**Created:** [June 1, 2023, 8:55am UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303 "2023-06-01T08:55:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PyMichael](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@PyMichael](https://discuss.python.org/u/PyMichael)\
**Post date:** [June 1, 2023, 8:55am UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303/1 "2023-06-01T08:55:57Z")

</div>

Short time ago, I started with PYTHON and have few applications running. Up to now, I did not take into account, if pip packages have been installed from repository or using `pip install`.  
Actually I’m thinking to clean up in order to use [pipx](https://pypa.github.io/pipx/) from now on. `pip freeze` shows 205 packages, `pip list` additionally:

```auto
pip 23.1.2
setuptools 65.5.0
wheel 0.40.0

```

How should I proceed? Thank you for your advice!

---

<div class="post-metadata">

**Author:** ![swills1](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@swills1](https://discuss.python.org/u/swills1)\
**Post date:** [June 1, 2023, 5:21pm UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303/2 "2023-06-01T17:21:12Z")

</div>

I don’t follow the question. Couldn’t you `pip list` then `pip uninstall ...`?

As far as virtual environments - use them to isolate package versions to projects.

Basically - build each project in its own virtual environment so that it’s dependencies are isolated.

I use [Poetry](https://python-poetry.org/) for my workflow. It creates a virtualenv for the project automatically.

---

<div class="post-metadata">

**Author:** ![PyMichael](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@PyMichael](https://discuss.python.org/u/PyMichael)\
**Post date:** [June 2, 2023, 6:57am UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303/3 "2023-06-02T06:57:16Z")

</div>

Thank you Steven @swills1

> [@swills1](#):
>
> Couldn’t you `pip list` then `pip uninstall ...`?  
> …  
> Basically - build each project in its own virtual environment so that it’s dependencies are isolated.

You mean to uninstall the ~ 200 pip-packages and start from scratch?  
I’d appreciate also an advice to setup and use virtualenv for different projects (PYTHON applications).

---

<div class="post-metadata">

**Author:** ![cameron](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/cameron/32/2658_2.png) [@cameron](https://discuss.python.org/u/cameron)\
**Post date:** [June 2, 2023, 7:19am UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303/4 "2023-06-02T07:19:32Z")

</div>

I’m a venv/pip person and haven’t used `pipx`.

My own approach is basicly this:

```
 cd my_project_dir
 python3 -m venv venv # make an empty virtualenv in "venv"
                         # pick your preferred subdir name
 ./venv/bin/python3 -m pip install ...whatever...

```

Whenever you invoke `./venv/bin/python3` it runs the Python associated  
with the virtual environment you made just here, unique to this project.  
This is what Steven meant about “isolated”: a distinct venv per project  
with just what you wanted for that project.

Personally, I don’t use the “activate” command (which fiddles your shell  
environment), because I only want the venv Python when running the  
project code, not for general stuff. So I’ve got a 'dev" command which:

- prepends the project Python source tree to `$PYTHONPATH`
- prepends `./venv/bin` to $PATH (with the full path to venv)
- execs its arguments

So when I want to run the project Python I do something like:

```
 dev python3 ...whatever...

```

which will find the `python3` from the venv.

Typically projects keep their required third party packages in a  
`requirements.txt` file; that both documents them and also means you can  
reinstall the packages for yourproject in the venv with:

```
 dev python3 -m pip install -r requirements.txt

```

(adjust to suit).

Cheers,  
Cameron Simpson [cs@cskk.id.au](mailto:cs@cskk.id.au)

---

<div class="post-metadata">

**Author:** ![kknechtel](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kknechtel](https://discuss.python.org/u/kknechtel)\
**Post date:** [June 2, 2023, 10:38am UTC](https://discuss.python.org/t/newbie-trying-to-understand-pip-and-virtual-environment/27303/5 "2023-06-02T10:38:18Z")

</div>

> [@PyMichael](#):
>
> How should I proceed?

Specifically what problem are you trying to solve?

> [@PyMichael](#):
>
> `pip freeze` shows 205 packages

Does this cause a problem? Why/how?

What exactly are you “trying to understand” here?
