-2

I want to install this library: https://github.com/stefanfoulis/django-phonenumber-field

I have done like this:

(venv) michael@michael:~/PycharmProjects/client$ pip install django-phonenumber-field[phonenumbers]
Requirement already satisfied: django-phonenumber-field[phonenumbers] in ./venv/lib/python3.8/site-packages (5.1.0)
Requirement already satisfied: Django>=2.2 in ./venv/lib/python3.8/site-packages (from django-phonenumber-field[phonenumbers]) (3.2.3)
Collecting phonenumbers>=7.0.2; extra == "phonenumbers"
  Downloading phonenumbers-8.12.23-py2.py3-none-any.whl (2.6 MB)
     |████████████████████████████████| 2.6 MB 2.8 MB/s 
Requirement already satisfied: sqlparse>=0.2.2 in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (0.4.1)
Requirement already satisfied: asgiref<4,>=3.3.2 in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (3.3.4)
Requirement already satisfied: pytz in ./venv/lib/python3.8/site-packages (from Django>=2.2->django-phonenumber-field[phonenumbers]) (2021.1)
Installing collected packages: phonenumbers
Successfully installed phonenumbers-8.12.23

We can see that this library has installed its dependency: phonenumbers library.

But now I want to write in requirements.txt that I need django-phonenumber-field of a certain release. So that its dependency should be installed as appropriate.

In other words how to write requirements.txt for future pip install -r requirements.txt.

Could you help me here?

=====ADDED LATER======= pip freeze > requirements.txt doesn't seem to be appropriate as it will contain all the dependencies. It will become overburden with dependencies. I will forget why a particular library is installed. Whether it is a dependency at all. If it is, what library depends on it.

I want to keep requirements.txt as clear as possible. In this particular example I want just one directive: install django-phonenumber-field==5.1.0 and manage dependencies yourself.

Wrong way (bloated and unclear what to delete if I stop using the library):

django-phonenumber-field==5.1.0
phonenumbers==8.12.23 

What I want: django-phonenumber-field==5.1.0 [and all dependencies]

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Kifsif
  • 3,477
  • 10
  • 36
  • 45

2 Answers2

1

As @jonrsharpe said, you can use pip freeze which lists all your dependencies, and redirect the output to your requirements.txt file to update it.

pip freeze > requirements.txt
Charly
  • 83
  • 1
  • 8
  • No, you will never find out what you installed yourself and what are the dependencies. – Kifsif May 16 '21 at 10:06
  • 1
    @Kifsif Ah I see, the only solution I can think of is writing it to `requirements.txt` yourself... but that means having to keep track of any dependency change you make. – Charly May 16 '21 at 10:26
  • Pip resolves dependencies. I just don't know how to do it in this particular case. – Kifsif May 16 '21 at 10:28
0

The simple way is to create a text file, type the shell commands in, save it and the rename it from .txt to .bat. Now you can double click the file and it installs the requirements. You could probably even execute the .bat

Xyndra
  • 110
  • 1
  • 11