Pip冻结实际导入的包

时间:2016-11-03 10:27:53

标签: python pip virtualenv

我有一个(Django)项目有很多进口,我没有使用virtualenv。有没有办法

Manifest-Version: 1.0
Bundle-Description: Flying Saucer is a CSS 2.1 renderer written in Jav
 a.  This artifact supports PDF output.
Bundle-License: http://www.gnu.org/licenses/lgpl.html
Bundle-SymbolicName: org.xhtmlrenderer.flying-saucer-pdf
Archiver-Version: Plexus Archiver
Built-By: u0400072
Bnd-LastModified: 1478168053263
Bundle-ManifestVersion: 2
Embed-Dependency: itext
Import-Package: com.apple.mrj,com.lowagie.toolbox,javax.crypto,javax.i
 mageio,javax.imageio.metadata,javax.imageio.plugins.jpeg,javax.imagei
 o.stream,javax.swing,javax.xml.parsers,javax.xml.transform,javax.xml.
 transform.dom,javax.xml.transform.sax,javax.xml.transform.stream,org.
 bouncycastle.asn1,org.bouncycastle.asn1.cmp,org.bouncycastle.asn1.cms
 ,org.bouncycastle.asn1.ocsp,org.bouncycastle.asn1.pkcs,org.bouncycast
 le.asn1.tsp,org.bouncycastle.asn1.x509,org.bouncycastle.cms,org.bounc
 ycastle.crypto,org.bouncycastle.crypto.engines,org.bouncycastle.crypt
 o.modes,org.bouncycastle.crypto.paddings,org.bouncycastle.crypto.para
 ms,org.bouncycastle.jce.provider,org.bouncycastle.ocsp,org.bouncycast
 le.tsp,org.w3c.dom,org.xhtmlrenderer.context,org.xhtmlrenderer.css.co
 nstants,org.xhtmlrenderer.css.extend,org.xhtmlrenderer.css.parser,org
 .xhtmlrenderer.css.sheet,org.xhtmlrenderer.css.style,org.xhtmlrendere
 r.css.style.derived,org.xhtmlrenderer.css.value,org.xhtmlrenderer.ext
 end,org.xhtmlrenderer.layout,org.xhtmlrenderer.render,org.xhtmlrender
 er.resource,org.xhtmlrenderer.simple.extend,org.xhtmlrenderer.swing,o
 rg.xhtmlrenderer.util,org.xml.sax,org.xml.sax.helpers
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))"
Tool: Bnd-3.2.0.201605172007
Embedded-Artifacts: itext-2.1.7.jar;g="com.lowagie";a="itext";v="2.1.7
 "
Export-Package: org.xhtmlrenderer.pdf;uses:="org.w3c.dom,org.xhtmlrend
 erer.css.constants,org.xhtmlrenderer.css.parser,org.xhtmlrenderer.css
 .style,org.xhtmlrenderer.css.value,org.xhtmlrenderer.extend,org.xhtml
 renderer.layout,org.xhtmlrenderer.render,org.xhtmlrenderer.resource,o
 rg.xhtmlrenderer.simple.extend,org.xhtmlrenderer.swing,org.xml.sax";v
 ersion="9.0.10",org.xhtmlrenderer.pdf.util;uses:="org.w3c.dom,org.xht
 mlrenderer.pdf";version="9.0.10",org.xhtmlrenderer.simple;uses:="java
 x.swing,org.w3c.dom,org.xhtmlrenderer.css.extend,org.xhtmlrenderer.cs
 s.sheet,org.xhtmlrenderer.extend,org.xhtmlrenderer.layout,org.xhtmlre
 nderer.swing,org.xhtmlrenderer.util";version="9.0.10"
Bundle-Name: Flying Saucer PDF Rendering
Bundle-Version: 9.0.10.SNAPSHOT
Bundle-ClassPath: .,itext-2.1.7.jar
Embed-Transitive: true
Created-By: Apache Maven Bundle Plugin
Build-Jdk: 1.8.0_102

只有在项目中某处实际导入的Python包,即我的项目需要它们吗?

pip freeze

会列出我系统中安装的所有软件包,但我只需要那些项目使用的软件包。

1 个答案:

答案 0 :(得分:2)

手动解决方案可能

使用grep

查找包
grep -r import ./*/*[.py] > j.t

使用python

迭代j.t中的所有行
fromIndex = line.find('from')
importIndex = line.find('import')
if fromIndex != -1:
    return = line[fromIndex + 5 : importIndex - 1][5:]
else:
    return = line[importIndex + 7:]

删除所有重复项

在虚拟环境中冻结pip以查找版本号

Pip冻结虚拟环境以找到其他版本号