Delete unused packages from requirements file

前端 未结 3 595
生来不讨喜
生来不讨喜 2020-12-07 17:27

Is there any easy way to delete no-more-using packages from requirements file?

I wrote a bash script for this task but, it doesn\'t work as I expect

3条回答
  •  盖世英雄少女心
    2020-12-07 18:04

    The best bet is to use a (fresh) python virtual-env with no packages, or only those you definitely know you need, test your package - installing missing packages with pip as you hit problems which should be quite quick for most software then use the pip freeze command to list the packages you really need. Better you you could use pip wheel to create a wheel with the packages in.
    The other approach would be to:

    1. Use pylint to check each file for unused imports and delete them, (you should be doing this anyway),
    2. Run your tests to make sure that it was right,
    3. Use a tool like snakefood to generate your new list of dependencies

    Note that for any dependency checking to work well it is advisable to avoid conditional import and import within functions.

    Also note that to be sure you have everything then it is a good idea to build a new virtual-env and install from your dependencies list then re-test your code.

提交回复
热议问题