saul.shanabrook
saul.shanabrook

Reputation: 3168

How to freeze packages installed only in the virtual environment?

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

Upvotes: 79

Views: 85579

Answers (8)

Furkan Köksaldı
Furkan Köksaldı

Reputation: 49

I did try everything, even i inside venv it not worked. This code worked for me. It shows only pip packages in venv.

venv\Scripts\python.exe venv\Scripts\pip.exe freeze > requirements.txt 

Upvotes: 2

Codey
Codey

Reputation: 1233

For me (macOS) the following worked

path/to/venv/bin/pip3 freeze -l

Upvotes: 7

orangecaterpillar
orangecaterpillar

Reputation: 866

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

Upvotes: 2

Agustin Maria Pardo
Agustin Maria Pardo

Reputation: 11

python venv/Path_to/bin/pip freeze -l 

Upvotes: 1

Muneeb Ali
Muneeb Ali

Reputation: 2116

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.

Upvotes: 120

Dima Bildin
Dima Bildin

Reputation: 1553

Try the following command:

pip -E /path/to/env/ freeze

Upvotes: -1

César
César

Reputation: 10119

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.

Upvotes: -3

Bitcoin Mexico
Bitcoin Mexico

Reputation: 139

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/.

Upvotes: 13

Related Questions