1

On my project located in a folder named example contains all the .py files of the project. Also my project uses some packages provided via pip, but when I need to upload to the common git repo for my coleagues in order to use it I need somwhow to "index" or to "list" the required packages that I installed via pip in order to download them.

In other words I am looking a similar functionality with node's npm or php's composer where there is the ability to save all the references for my dependencies so my coleagues to download them via either npm install or composer install. So I am asking how can I achieve similar functionality with pip?

Edit 1:

I only have installed some pip packages how I will get the one I import into my source code?

I mean on my project's spurce i habe entries like:

import ^package_name^
from ^package_name^ import ^some_function_or_class^

How I will locate the pip packages I install by looking the import entries?

Community
  • 1
  • 1
Dimitrios Desyllas
  • 9,082
  • 15
  • 74
  • 164
  • Possible duplicate of [How can I get a list of locally installed Python modules?](https://stackoverflow.com/questions/739993/how-can-i-get-a-list-of-locally-installed-python-modules) – yinnonsanders Jul 24 '17 at 14:40
  • I don't understand what you are asking for in your _Edit 1_. Could you clarify? – Paco H. Jul 24 '17 at 14:52

1 Answers1

4

What you are looking for are requirements files.

https://pip.pypa.io/en/stable/user_guide/#requirements-files

If you wanted to save all your current packages you could do pip freeze > requirements.txt, but I wouldn't recommend it as this would add not only the packages your script needs, but also the requirements of your requirements and so on. For example:

$ pip freeze
no packages installed
$ pip install requests
$ pip freeze
certifi==2017.4.17
chardet==3.0.4
idna==2.5
requests==2.18.1
urllib3==1.21.1

So in this example only requests should be in your requirements files, but if you dump pip freeze you have some extra packages.

Your requirements file could look like this:

# This is the contests of requirements.txt
requests>=2.18.1,<3.0.0

And to install it you would simply have to do pip install -r requirements.txt.


If you start working on different projects with different requirements you will definitely need to know about virtual environments. It's a way to have different set of python interpreters and packages installed. Similar to how npm will install the packages in your current folder.

Paco H.
  • 2,034
  • 7
  • 18