Using easy_install inside a python script?

后端 未结 5 1847
小蘑菇
小蘑菇 2021-02-07 08:33

easy_install python extension allows to install python eggs from console like:

easy_install py2app

But is it possible to access easy_install fu

5条回答
  •  遇见更好的自我
    2021-02-07 08:42

    The answer about invoking setuptools.main() is correct. However, if setuptools creates a .egg, the script will be unable to import the module after installing it. Eggs are added automatically to sys.path at python start time.

    One solution is to use require() to add the new egg to the path:

    from setuptools.command import easy_install
    import pkg_resources
    easy_install.main( ['mymodule'] )
    pkg_resources.require('mymodule')
    

提交回复
热议问题