我pip freeze > requirements.txt
用来收集我安装的所有软件包。但是开发了很多天,有些包现在没用了。如何找到这些未使用的包并删除它们,以使我的项目更加清晰?
我有几个python项目,在pip需求文件中列出了不同的依赖项集.我已经开始考虑将代码移植到python 3,但我需要知道我的依赖项是否已存在.
是否有可能检查requirements.txt
文件中的哪些包支持python 3,哪些不支持?
示例requirements.txt
内容:
mysql-python==1.2.5
lxml==3.3.4
Fabric==1.8.0
Run Code Online (Sandbox Code Playgroud)
从这个列表中,只lxml
支持python 3.
只是旁注.
有一个Python 3 Wall of Superpowers(python3wos项目)显示了对流行python包的python 3支持.
据我了解,python3wos
定期解析Python Package Index
HTML页面和检查的Programming Language :: Python :: 3
文字来定义一个包是否支持Python 3支与否.没有什么比在PyPI上抓取html更简单了吗?
我希望在 GitHub 上放置一个 python 程序,并让其他人在他们的计算机上使用各种操作系统下载并运行它。我对 python 比较陌生,但使用它已经足够了,注意到让所有包含的模块的各种版本一起工作可能会有问题。我刚刚发现了使用requirements.txt
(使用pipreqs
命令生成和部署pip install -r /path/to/requirements.txt
),但很惊讶地注意到它requirements.txt
实际上并没有说明正在使用哪个版本的python,所以显然它本身并不是完整的解决方案。所以我的问题是:需要什么样的规范/文件/其他东西来确保下载我的项目的人实际上能够以最少的问题运行它。
编辑:我的计划是以得到最多票数的答案为指导。但到目前为止,在 4 个回答和 127 次观看之后,没有一个回答获得了一个赞。如果某些答案不好,那么查看一些关于为什么它们不好的评论会很有用。
我的需求文件中有这一行
django>=1.10,<1.11
Run Code Online (Sandbox Code Playgroud)
这是否意味着我需要拥有Django版本>= 1.10
然后不到1.11
?
Torch 文档说使用
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
Run Code Online (Sandbox Code Playgroud)
安装最新版本的 PyTorch。这在我手动执行时有效,但是当我将其添加到 req.txt 并执行时pip install -r req.txt
,它失败并显示 ERROR: No matching distribution
.
编辑:从 req.txt 添加整行并在此处添加错误。
torch==1.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.htmltorch==1.4.0+cpu
Run Code Online (Sandbox Code Playgroud)
ERROR: Could not find a version that satisfies the requirement torch==1.4.0+cpu (from -r requirements.txt (line 1)) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 0.3.1, 0.4.0, 0.4.1, 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0)
ERROR: No matching distribution found for torch==1.4.0+cpu (from -r requirements.txt (line 1))
Run Code Online (Sandbox Code Playgroud) 我想知道如何为我的Python 3应用程序创建合适的requirements.txt?
包管理器JavaScript
喜欢npm
和yarn
使用 apackage.json
来指定“顶级”依赖项,并创建一个锁定文件来跟踪作为结果安装的所有包(即顶级和子级依赖项)的特定版本。
此外,package.json
允许我们区分顶级依赖项的类型,例如production和development。
对于Python
,另一方面,我们有pip
。我想pip
相当于一个lock
-file 将是pip freeze > requirements.txt
.
但是,如果您只维护这个单个requirements.txt
文件,则很难区分顶级和子级依赖项(例如pipdeptree -r
,您需要弄清楚这些)。如果您想删除或更改顶级依赖项,这可能会很痛苦,因为很容易留下孤立的包(据我所知,当您创建一个包时,pip
不会删除子依赖项pip uninstall
)。
现在,我想知道:是否有一些约定来处理这些requirements
文件的不同类型并区分顶级和子级依赖关系pip
?
例如,我可以想象有 arequirements-prod.txt
只包含生产环境的顶级要求,作为 , 的(简化)等价物package.json
,而 arequirements-prod.lock
包含 , 的输出pip freeze
,并充当我的 -lock
文件。此外,我可以有一个requirements-dev.txt
用于开发的依赖项,等等。
我想知道这是要走的路,还是有更好的方法。
ps 同样的问题可以问conda …
我有一个environment.yml
文件,但不想使用 Conda:
name: foo
channels:
- defaults
dependencies:
- matplotlib=2.2.2
Run Code Online (Sandbox Code Playgroud)
是否可以像文件一样pip
安装依赖项?environment.yml
requirements.txt
我尝试过pip install -r environment.yml
,但它不适用于pip==22.1.2
.
所以我有这个项目有许多从pip安装的依赖项,并记录在requirements.txt中我需要添加另一个依赖项,现在pip上不存在,我把它作为某个地址的RPM.作为要求安装它的最Pythonic方法是什么?谢谢!代码将在RHEL和Fedora上运行
python ×10
requirements.txt ×10
pip ×5
conda ×2
django ×2
python-2.7 ×2
dependencies ×1
fedora ×1
package ×1
porting ×1
python-3.x ×1
pytorch ×1
travis-ci ×1