如何找到我的项目中使用的所有包及其版本?

2024-04-26 20:41:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python项目,我想为它。所以我需要找到我的项目中使用的所有包。 有简单的方法吗?在


Tags: 项目方法
3条回答

我评论的原始答案:

您可以使用pip freeze列出所有已安装的包以及特定版本:

pip freeze > requirements.txt

这将很好地工作,尤其是当您使用virtualenv时。如果不是,并且您只想列出特定项目中请求的包,请考虑@Sidon的answer。在

皮普雷克斯

pip冻结列出所有安装的包,使用pipreqs。PIPREQ生成要求.txt基于导入的任何项目的文件。在

pip install pipreqs


Usage:
    pipreqs [options] <path>

Options:
     use-local           Use ONLY local package info instead of querying PyPI
     pypi-server <url>   Use custom PyPi server
     proxy <url>         Use Proxy, parameter will be passed to requests library. You can also just set the
                          environments parameter in your terminal:
                          $ export HTTP_PROXY="http://10.10.1.10:3128"
                          $ export HTTPS_PROXY="https://10.10.1.10:1080"
     debug               Print debug information
     ignore <dirs>...    Ignore extra directories
     encoding <charset>  Use encoding parameter for file open
     savepath <file>     Save the list of requirements in the given file
     print               Output the list of requirements in the standard output
     force               Overwrite existing requirements.txt

Project on github

您可以通过运行pip freeze > requirements.txt来完成此操作。 我建议你在这里看一下这个link,因为它解释得很好。在

pip freeze命令按照documentation执行以下操作:

Output installed packages in requirements format.

因此,当运行pip freeze > requirements.txt时,您正在将已安装的包写入.txt文件中。在

相关问题 更多 >