63

How to freeze packages installed only in the virtual environment, that is, without the global ones?

nbro
  • 13,796
  • 25
  • 99
  • 185
saul.shanabrook
  • 2,886
  • 3
  • 29
  • 47

7 Answers7

103

You need to use the -l or --local option to freeze only the local packages (and not the global ones)

pip freeze -l > requirements.txt 

Make sure you are working in the virtualenv before doing pip freeze -l.

NoName
  • 8,934
  • 4
  • 27
  • 47
Muneeb Ali
  • 1,946
  • 1
  • 15
  • 8
8

Only local packages on virtual environment

pip freeze -l > requirements.txt # or --local instead of -l

Only local packages installed by the user on virtual environment

pip freeze --user > requirements.txt

See the documentation for further details: https://pip.pypa.io/en/stable/reference/pip_freeze/.

nbro
  • 13,796
  • 25
  • 99
  • 185
6

For me (macOS) the following worked

path/to/venv/bin/pip3 freeze -l
Codey
  • 979
  • 1
  • 11
  • 28
2

I'm on Windows 10, python 3.6, with my virtual environment called env activated using command prompt I found that pip freeze -l does not work (error), python -m pip freeze -l does not work (gets global packages) but changing into my virtual environment Scripts directory and running pip freeze or pip freeze -l works. Here is an example of this solution/work-around with my virtual environment, env:

cd \env\Scripts
pip freeze > ..\..\requirements.txt
1
python venv/Path_to/bin/pip freeze -l 
Dharman
  • 26,923
  • 21
  • 73
  • 125
-1

Install whatever you need to freeze in your virtual environment, and then

pip freeze > requirements.txt

After that install the packages in the virtual environment that you do not want to freeze.

nbro
  • 13,796
  • 25
  • 99
  • 185
César
  • 9,663
  • 6
  • 50
  • 71
-1

Try the following command:

pip -E /path/to/env/ freeze
nbro
  • 13,796
  • 25
  • 99
  • 185
Dima Bildin
  • 1,523
  • 10
  • 14