Using easy_install inside a python script?

后端 未结 5 1844
小蘑菇
小蘑菇 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:59

    What specifically are you trying to do? Unless you have some weird requirements, I'd recommend declaring the package as a dependency in your setup.py:

    from setuptools import setup, find_packages
    setup(
        name = "HelloWorld",
        version = "0.1",
        packages = find_packages(),
        scripts = ['say_hello.py'],
    
        # Project uses reStructuredText, so ensure that the docutils get
        # installed or upgraded on the target machine
        install_requires = ['docutils>=0.3'],
    
        package_data = {
            # If any package contains *.txt or *.rst files, include them:
            '': ['*.txt', '*.rst'],
            # And include any *.msg files found in the 'hello' package, too:
            'hello': ['*.msg'],
        }
    
        # metadata for upload to PyPI
        author = "Me",
        author_email = "me@example.com",
        description = "This is an Example Package",
        license = "PSF",
        keywords = "hello world example examples",
        url = "http://example.com/HelloWorld/",   # project home page, if any
    
        # could also include long_description, download_url, classifiers, etc.
    )
    

    The key line here is install_requires = ['docutils>=0.3']. This will cause the setup.py file to automatically install this dependency unless the user specifies otherwise. You can find more documentation on this here (note that the setuptools website is extremely slow!).

    If you do have some kind of requirement that can't be satisfied this way, you should probably look at S.Lott's answer (although I've never tried that myself).

提交回复
热议问题