[英]Pip freeze packages that are actually imported
I have a (Django) project with lots of imports that I started without virtualenv.我有一个(Django)项目,其中有很多导入,但我在没有 virtualenv 的情况下开始。 Is there a way to
有没有办法
pip freeze
only the Python packages that are actually imported somewhere in the project, ie they are required by my project?只有实际导入项目中某处的 Python 包,即我的项目需要它们?
pip freeze
would list all the packages installed in my system, but I would only need those ones that are used by my project.将列出我系统中安装的所有软件包,但我只需要我的项目使用的那些软件包。
A manual solution could be手动解决方案可能是
Find the packages with grep使用 grep 查找包
grep -r import ./*/*[.py] > j.t
Iterate all the lines in jt
with python用python迭代
jt
所有行
fromIndex = line.find('from')
importIndex = line.find('import')
if fromIndex != -1:
return = line[fromIndex + 5 : importIndex - 1][5:]
else:
return = line[importIndex + 7:]
Remove all the duplicates删除所有重复项
Pip freeze in the virtual env for find the version number在虚拟环境中冻结 Pip 以查找版本号
Pip freeze out the virtual env for find the other version number Pip 冻结虚拟环境以查找其他版本号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.