Python 生成工程需要依賴包

網上這個答案好多,在我眼裏根dog shit一樣,先說結果,然後再分析。

$pip3 install pipreqs
$cd 到項目
$pipreqs ./
$pip3 install -r requirements.txt

到此結束。


  • 下面來說下這個工具,
$pip3 search pipreqs
pipreqs (0.4.10)            - Pip requirements.txt generator based on imports in project
pipreqs-amasad (0.4.10)     - Pip requirements.txt generator based on imports in project
pipreqs-spenly (0.4.10)     - Pip requirements.txt generator based on imports in project
pipreqs-update (2019.4.13)  - update pip requirements file with latest versions

可以看到他是通過檢索imports來生成requirements.txt

$pipreqs -h
pipreqs - Generate pip requirements.txt file based on imports

Usage:
    pipreqs [options] [<path>]

Arguments:
    <path>                The path to the directory containing the application
                          files for which a requirements file should be
                          generated (defaults to the current working
                          directory).

在項目目錄下執行,如果已經有一個req文件還需要帶上--force來覆寫。

WARNING: Requirements.txt already exists, use --force to overwrite it




  • 然後來分析下我爲什麼說網上很多結果都是dog shit
    很多結果是這麼寫的:

$pip freeze > requirements.txt

我們來看下freeze是什麼:

$pip3 -h

Usage:   
  pip3 <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

可以看到這個是輸出你當前環境的所有依賴,並不是這個工程的!!!這不是誤人麼。





知識共享許可協議
本作品採用知識共享署名-非商業性使用-相同方式共享 4.0 國際許可協議進行許可。

發佈了44 篇原創文章 · 獲贊 18 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章