Last updated: Apr 10, 2024
Reading timeยท3 min

The difference between pip freeze and pip list is that:
pip freeze outputs the installed by the user packages in a requirements
format that can be used to generate a requirements.txt file.pip list outputs all installed packages, including editables.pip freeze is used to generate a requirements.txt fileYou will most often use the pip freeze command to generate a
requirements.txt file.
pip freeze > requirements.txt pip3 freeze > requirements.txt
pip freeze to a file called requirements.txt.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
A requirements.txt file can only be generated from the output of the
pip freeze command, not from
the output of pip list.

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 list command outputs the packages in a different formatThe pip list command also shows the installed packages and their versions but in a different format.

pip freeze command doesn't output packages that pip depends on by default, e.g. wheel and setuptools, whereas the pip list command does.You can use the --all option if you need to include the
pip,
setuptools, distrubute and
wheel packages in the
output of pip freeze.
pip freeze --all
The 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 the 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 the package in your virtual environment pip install requests # ๐๏ธ Optionally install packages from a `requirements.txt` file pip install -r requirements.txt pip3 install -r requirements.txt
If the python -m venv venv command doesn't work, try one of the following
commands:
python3 -m venv venvpy -m venv venvMake 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:
--no-cache-dir option