How to retrieve pip requirements (freeze) within Python?

后端 未结 4 762
北海茫月
北海茫月 2020-12-17 16:41

I posted this question on the git issue tracker: https://github.com/pypa/pip/issues/2969

Can we have some manner of calling pip freeze/list within python, i.e. not a

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-17 17:14

    The other answers here are unsupported by pip: https://pip.pypa.io/en/stable/user_guide/#using-pip-from-your-program

    According to pip developers:

    If you're directly importing pip's internals and using them, that isn't a supported usecase.

    try

    reqs = subprocess.check_output([sys.executable, '-m', 'pip', 'freeze'])
    

提交回复
热议问题