The difference between
pip freeze and
pip list is that:
pip freezeoutputs the installed by the user packages in a requirements format that can be used to generate a
pip listoutputs all installed packages, including editables.
pip freezeis used to generate a
You will most often use the
pip freeze command to generate a
pip freeze > requirements.txt pip3 freeze > requirements.txt
pip freezeto a file called
The requirements.txt file can be used to install the packages and recreate the environment.
pip install -r requirements.txt pip3 install -r requirements.txt
requirements.txt file can only be generated from the output of the
pip freeze command, not from
the output of
The names of packages and the specific versions are separated by two equal signs
which is the syntax used by
pip to install a specific version of a package.
pip install requests==2.28.0 pip3 install requests==2.28.0
pip listcommand outputs the packages in a different format
The pip list command also shows the installed packages and their versions but in a different format.
pip freezecommand doesn't output packages that pip depends on by default, e.g.
setuptools, whereas the
pip listcommand does.
pip freeze --all
pip list outputs all installed packages, including editables, whereas
pip freeze shows the packages the user installed and their dependencies.
If you don't use a virtual environment, it is recommended to create one as they make management of packages much easier.
# 👇️ optionally store currently installed packages in a file pip freeze > requirements.txt pip3 freeze > requirements.txt # 👇️ use correct version of Python when creating VENV python -m venv venv # 👇️ activate on Unix or MacOS source venv/bin/activate # 👇️ activate on Windows (cmd.exe) venv\Scripts\activate.bat # 👇️ activate on Windows (PowerShell) venv\Scripts\Activate.ps1 # 👇️ Upgrade pip pip install --upgrade pip # 👇️ install package in virtual environment pip install requests # 👇️ optionally install packages from a `requirements.txt` file pip install -r requirements.txt pip3 install -r requirements.txt
python -m venv venv command doesn't work, try one of the following
python3 -m venv venv
py -m venv venv
Make sure to use the correct activation command depending on your operating system.
Note that the name
requirements.txt is just a convention. You can use any to
store the output of the
pip freeze command and you can have as many
requirements files as necessary.
You can learn more about the related topics by checking out the following tutorials: