获取python项目使用的所有模块/软件包 [英] Get all modules/packages used by a python project

查看:449
本文介绍了获取python项目使用的所有模块/软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Python GUI应用程序.现在,我需要知道应用程序链接到的所有库.这样我就可以检查所有库的许可证兼容性.

I have a python GUI application. And now I need to know what all libraries the application links to. So that I can check the license compatibility of all the libraries.

我尝试使用strace,但是strace似乎报告了所有软件包,即使应用程序未使用它们.

I have tried using strace, but strace seems to report all the packages even if they are not used by the application.

而且,我尝试使用python ModuleFinder,但是它只返回python2.7内的模块,而不返回链接的系统级包.

And, I tried python ModuleFinder but it just returns the modules that are inside python2.7 and not system level packages that are linked.

那么我有什么办法可以从应用程序中获取所有链接的库?

So is there any way I can get all the libraries that are linked from my application?

推荐答案

您可以尝试使用该库 https://github.com/bndr/pipreqs 根据指南找到 https://www.fullstackpython.com/application-dependencies.html

You can give a try to the library https://github.com/bndr/pipreqs found following the guide https://www.fullstackpython.com/application-dependencies.html

库pipreqs是pip可安装的,并自动生成文件requirements.txt.它包含所有导入库,这些导入库包含您在virtualenv或正确安装的python中使用的版本.

The library pipreqs is pip installable and automatically generates the file requirements.txt. It contains all the imports libraries with versions you are using in the virtualenv or in the python correctly installed.

只需输入:

pip install pipreqs
pipreqs /home/project/location

它将打印:

INFO: Successfully saved requirements file in /home/project/location/requirements.txt

此外,它与 pip install -r 命令兼容:如果您需要创建项目的venv或使用兼容的库更新当前的python版本,则只需键入:

In addition it is compatible with the pip install -r command: if you need to create a venv of your project, or update your current python version with compatible libraries, you just need to type:

pip install -r requirements.txt

我遇到了同样的问题,这个库为我解决了.不知道它是否适用于多层依赖关系,即如果您嵌套了层次的依赖库.

I had the same problem and this library solved it for me. Not sure if it works for multiple layers of dependencies i.e. in case you have nested level of dependent libraries.

-编辑-更新:

如果要寻找更高级的版本管理器,请同时考虑pyvenv https://github.com/pyenv/pyenv .它将virtualenvpipreqs混合在同一工具中,并对pipreqs的版本规范进行了一些改进.

If looking for a more sophisticated version manager, please consider as well pyvenv https://github.com/pyenv/pyenv. It blends virtualenv and pipreqs in the same tool, with some improvements over the version specification of pipreqs.

这篇关于获取python项目使用的所有模块/软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆