How to package shared objects that python modules depend on?

假如想象 提交于 2021-02-18 11:43:11

问题


I have a python package implemented in C++ that I am distributing using setuptools. My C++ code depends on some shared objects, specifically the boost.python library. How should I distribute these shared objects? At the moment I ask the package user to install the boost C++ libraries separately but I would rather bundle everything in one setuptools distribution to make it easier for him/her. At the moment they must set up the boost libraries and their LD_LIBRARY_PATH environment variable in addition to installing my package.


回答1:


Declaring dependencies

There is an option in setup.py called install_requires = [""] : Ex :

setup(
    name='django-cherrypy',
    version='0.1',
    packages=packages,
    license='LICENSE',
    description='cherrypy, running under django',
    long_description=open('README.md').read(),
    author='Calvin Cheng',
    author_email='calvin@calvinx.com',
    install_requires=['cherrypy-wsgiserver'],
    extra_requires=['newrelic'],
    url='https://github.com/od-eon/django-cherrypy',
)

This setup ask for chrerryPy WSGI server library.

Bundle Everything

Everything is explained here : http://pythonhosted.org/distribute/setuptools.html#declaring-dependencies

Depedencies in PiPy :

  1. When your project is installed, either by using EasyInstall, setup.py install, or setup.py develop, all of the dependencies not already installed will be located (via PyPI), downloaded, built (if necessary), and installed.
  2. Any scripts in your project will be installed with wrappers that verify the availability of the specified dependencies at runtime, and ensure that the correct versions are added to sys.path (e.g. if multiple versions have been installed).
  3. Python Egg distributions will include a metadata file listing the dependencies

Dependencies that aren’t in PyPI

If your project depends on packages that aren’t registered in PyPI, you may still be able to depend on them, as long as they are available for download as:

  • an egg, in the standard distutils sdist format,
  • a single .py file,
  • or a VCS repository (Subversion, Mercurial, or Git). You just need to add some URLs to the dependency_links argument to setup().


来源:https://stackoverflow.com/questions/17484752/how-to-package-shared-objects-that-python-modules-depend-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!