C.W.K.
Stream
Lesson 03 of 05 · published

Daily pip Commands (with venv)

~13 min · pip, commands, venv, workflow

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

The single most important pip habit is never install packages globally. Always work inside a virtual environment (venv) per project. The four commands you'll type most are venv setup, install, freeze, and run.

python3 -m venv .venv creates a virtual environment in a .venv directory. source .venv/bin/activate activates it — your shell prompt prefixes with (.venv) and which python now points inside the venv. deactivate exits.

Inside the venv: pip install <pkg> installs a package into this venv only. pip install -r requirements.txt installs from a requirements file. pip install -e . does an editable install of the current directory — changes to source code take effect immediately, the standard way to develop a Python package.

pip freeze outputs every installed package in name==version format — the closest pip gets to a lockfile. Redirect to requirements.txt to capture your environment. pip list shows installed packages in a table format. pip show <pkg> shows version, install location, dependencies, and homepage for one package. pip uninstall <pkg> removes one (but does NOT remove its now-orphaned dependencies — that's pip's dirty-uninstall problem).

Code

The venv-first workflow·bash
# 1. Per-project venv
cd my-project
python3 -m venv .venv

# 2. Activate (zsh / bash)
source .venv/bin/activate

# Now your prompt shows (.venv); python and pip point inside the venv
which python
# /Users/you/my-project/.venv/bin/python

# 3. Install
pip install requests flask

# 4. Capture state
pip freeze > requirements.txt

# 5. Deactivate when done
deactivate
Reproduce on another machine·bash
# Clone the project; teammate's setup
cd my-project
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

# Now they have the same packages — but NOT necessarily the same
# transitive dep versions, unless requirements.txt was generated by
# a true locking tool like pip-tools, pip-compile, or uv.
Editable install for library development·bash
# In a Python package's source dir (with pyproject.toml or setup.py)
pip install -e .

# Now the package is importable from anywhere in this venv,
# AND your code edits take effect immediately — no reinstall needed.
# Standard workflow when developing a library.

External links

Exercise

Create a scratch directory, set up a venv, activate it, install three packages ('pip install requests rich httpx'), then 'pip freeze > requirements.txt'. Open the file — note that pip captured every transitive dep too. That flat output is requirements.txt's pretend-lockfile.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.