24

I would like to use for a small Python project this way of managing dependent modules: http://blog.zoomeranalytics.com/pip-install-t/

In brief, I would do:

cd myproject

pip install --target ./pip-libs --upgrade -r requirements.txt

then add ./pip-libs to PYTHONPATH and run my script.

This seems but I like to use use pip freeze and it does not allow me to do anything like

pip freeze --target pip-libs

to see packages installed in the folder. Of course, I can take a look inside but what is a standard way to show packages installed in a folder with --target? The only way I can think of is doing ls of pip-libs and then playing with grep, awk... Does not seem right.

I am not sure if there is a way, maybe it's not a good idea or I should request such functionality for pip.

Python 2.7.9.

BartoszGo
  • 340
  • 1
  • 2
  • 10

4 Answers4

16

Bit late to the party, but I ran in to the same issue and this seemed to solve it.

pip freeze --path ./pip-libs > requirements.txt
davo777
  • 286
  • 2
  • 15
  • Not sure when pip started supporting this, but I need to [update my version of pip](https://stackoverflow.com/a/15223296/1093087) before it would work for me. – klenwell Jan 31 '21 at 22:54
3

Note - this answer was given in 2016, and at the time was correct: the --path argument was added in 2019 in v19-2. So if you have before 19 you should probably upgrade. see https://pip.pypa.io/en/stable/news/#v19-2

Unfortunatly, you cant do it with pip freeze. The docs say that pip install installs into that target folder, but its still within your path. So pip freeze only shows what packages are installed, not what are installed in a particular place.

You could look at pip show which does contain information on where they are installed (see https://pip.pypa.io/en/stable/reference/pip_show/) but you would have to write some sed/awk or similar to do a grep on the line "Location" and then go back and get the package name.

The other option is to just look at the folders in the install folder and manually work out what the packages where from that... something like:

ls ./pip-libs | grep -v .dist-info

Jmons
  • 1,766
  • 17
  • 28
3

This should work

PYTHONPATH=./pip-libs pip freeze
Innuendo
  • 631
  • 5
  • 9
2
pip freeze --path [path location]

For current folder:

pip freeze --path .
Vikku
  • 31
  • 4