2016-11-03 54 views
2

我有一個(Django)項目,有很多我沒有virtualenv開始的進口。有沒有辦法來Pip凍結包,實際上是導入

pip freeze 

只有實際導入項目中某處的Python包,即他們是我的項目需要?

pip freeze 

會列出我係統中安裝的所有軟件包,但我只需要那些在我的項目中使用的軟件包。

+0

的可能的複製[如何列出導入模塊?](http://stackoverflow.com/questions/4858100/how-to-list-imported -modules) – JamesD

+0

你可以從'grep -r'import'。/' – Fi3

+0

@ Fi3開始:問題是這不會給出包含版本號的確切軟件包名稱 – Botond

回答

1

手動解決辦法是

找到包使用grep

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

迭代中的所有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:] 

刪除所有重複

皮普凍結在虛擬環境中找到版本號

皮普排擠虛擬ENV爲找到另一版本號