Embedding a Python library in my own package

前端 未结 4 1919
臣服心动
臣服心动 2020-12-08 00:44

How can I \'embed\' a Python library in my own Python package?

Take the Requests library, for instance. How could I integrate it into my own package, the objective b

4条回答
  •  鱼传尺愫
    2020-12-08 01:26

    While not a direct answer to your question. You may want to look at setuptools. By leveraging this package distribution mechanism you can describe your dependencies and when your package is "installed" all the dependent packages will be installed too. You would create a setup.py file at the top of your package structure similar to:

    from setuptools import setup, find_packages
    
    setup(
        name = 'MyPackage',
        version = '1.0',
        packages = find_packages(),
        ...
        install_requires = ['requests'],
        ...
    )
    

    this would be installed by the user

    python setup.py install
    

    Requests would be automatically installed too.

提交回复
热议问题