扫描python项目以查找所有已安装的第三方pip库,并生成基于requirements.txt的输出。

pip-module-scanner的Python项目详细描述


PIP模块扫描仪

Build StatusCode CoveragePyPI version

扫描python项目以查找所有已安装的使用的第三方pip库,并生成基于requirements.txt的输出。

安装

安装扫描仪很简单,可以克隆存储库并运行脚本,也可以通过pip安装,如下所示:

$ pip install pip-module-scanner

用法

使用扫描仪非常简单。打开一个终端,导航到你的项目文件夹,运行脚本,看着魔术发生在你眼前。示例:

$ cd ~/projects/my-awesome-project/
$ pip-module-scanner
foo==1.0.0
bar==2.1.0
baz==0.0.1

指定自定义路径

可以使用-p--path参数指定要在其中运行脚本的自定义路径。示例:

$ pip-module-scanner --path ~/projects/my-awesome-project/
foo==1.0.0 
bar==2.1.0
baz==0.0.1

将输出写入文件

可以使用-o--out参数将脚本的输出写入文件。示例:

$ cd ~/projects/my-awesome-project/
$ pip-module-scanner -o requirements.txt
$ cat requirements.txt
foo==1.0.0
bar==2.1.0
baz==0.0.1

在项目中集成代码

您可以很容易地将scanner代码集成到您自己的项目中,这样您就可以自己获得scanner的输出,或者修改类以满足您自己的需要。为此,您可以这样使用:

frompip_module_scanner.scannerimportScannerscanner=Scanner()scanner.run()# do whatever you want with the results here# example:forlibinscanner.libraries_found:print("Found module %s at version %s"%(lib.key,lib.version))

指定路径的工作方式与此类似,请确保同时导入ScannerException,因为它将检查您指定的路径是否为实际路径:

frompip_module_scanner.scannerimportScanner,ScannerExceptiontry:scanner=Scanner(path="~/projects/my-awesome-project/")scanner.run()# do whatever you want with the results here# example:forlibinscanner.libraries_found:print("Found module %s at version %s"%(lib.key,lib.version))exceptScannerExceptionase:print("Error: %s"%str(e))

对于那些喜欢一行程序的人(像我一样),你也可以用这个漂亮的小程序获得所有的库(我很体贴)

frompip_module_scanner.scannerimportScannerlibs=Scanner().run().libraries_found# Isn't it beautiful?

类定义

pip_module_scanner.scanner.scanner([string path[,string output]])

MethodArgumentTypeRequiredDescription
__init__pathstringnoDirectory to recursively scan through, defaults to current working directory.
outputstringnoOutput path to write the resutlts from ^{} to
runRuns the scan, output will be stored in ^{}
outputWrites the output to the console or a path specified in the constructor
PropertyTypeDescription
libraries_foundlist<pip._vendor.pkg_resources.EggInfoDistribution>List of all found pip libraries in your project, result from ^{}.

许可证

麻省理工学院许可证

版权所有(c)2016 Luke Paris

兹免费准许任何人取得副本 本软件和相关文档文件(“软件”)的 在软件中不受限制,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或出售 软件的副本,并允许软件的用户 在满足以下条件的情况下,可以这样做:

上述版权公告及本许可公告须包括在 软件的拷贝或大部分。

本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中, 不属于或与本软件有关,或使用或与本软件的其他交易有关。 软件。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java更改WSO2 IS证书会导致登录失败   安卓 Java随机行读取   JavaJComboBox留下了一条线索   用于嵌套对象的java Jasper报告   java动态生成Id值时,如何检索复选框的值   “拼接(a,b,…”的Java等价方法在JavaScript方法中   java在有子面板的jPanel上绘图   java生成时,在包“安卓”中找不到属性“text color”的资源标识符   java如何使用maven插件正确地构建Spring引导远jar?   readUTF中的java EOFEException   在Java中,按星期一到星期天进行排序   java MultiFormatReader无法读取qr,尽管qr是可扫描的   替换java字符串中未知数量的值   java将MySQL连接到Apache nutch   Java从3个不同的枚举中获取随机值   java我需要将多个JRadioButtongGroup和一个jcombobox连接到一个jbutton   java Android sqlite异常。无法实例化活动   如何使用单流创建Map<String,List<Long>>Java8?