简体   繁体   English

通过 pip -r requirements.txt 安装依赖项

[英]Install dependencies via pip -r requirements.txt

I want to install this library: https://github.com/stefanfoulis/django-phonenumber-field我想安装这个库: 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.我们可以看到这个库已经安装了它的依赖:phonenumbers 库。

But now I want to write in requirements.txt that I need django-phonenumber-field of a certain release.但是现在我想在 requirements.txt 中写下我需要某个版本的 django-phonenumber-field。 So that its dependency should be installed as appropriate .以便适当地安装它的依赖项

In other words how to write requirements.txt for future pip install -r requirements.txt .换句话说,如何为未来的pip install -r requirements.txt 编写 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. =====稍后添加======= pip freeze > requirements.txt 似乎不合适,因为它将包含所有依赖项。 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.我想让 requirements.txt 尽可能清晰。 In this particular example I want just one directive: install django-phonenumber-field==5.1.0 and manage dependencies yourself.在这个特定的示例中,我只需要一个指令:安装 django-phonenumber-field==5.1.0 并自己管理依赖项。

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]我想要什么:django-phonenumber-field==5.1.0 [和所有依赖项]

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.正如@jonrsharpe 所说,您可以使用pip freeze列出所有依赖项,并将 output 重定向到您的requirements.txt文件以更新它。

pip freeze > requirements.txt

The simple way is to create a text file, type the shell commands in, save it and the rename it from .txt to .bat .简单的方法是创建一个文本文件,输入 shell 命令,保存并将其从.txt重命名为.bat Now you can double click the file and it installs the requirements.现在您可以双击该文件并安装要求。 You could probably even execute the.bat你甚至可以执行.bat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM