栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

How should I handle importing third-party libraries within my setup.py script?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

How should I handle importing third-party libraries within my setup.py script?

I’m ignoring licensing issues in this answer. You definetly need to take these
into account before you really do a release.

Is it acceptable to rely on third-party libraries like this in setup.py

Yes, it is acceptable but generally these should be minimized, especially if
these are modules which have no obvious use for the end-user. Noone likes to
have packages they don’t need or use.

what is the recommended approach to using them?

There are basically 3 options:

  • Bootstrap them (for example use

    pip
    to programmatically install packages). For example
    setuptools
    provides an
    ez_setup.py
    file that can be used to bootstrap
    setuptools
    . Maybe that can be customized to download and install
    appdirs
    .

  • Include them (especially if it’s a small package) in your project. For example

    appdirs
    is basically just a single file module. Pretty easy to copy and maintain in your project. Be very careful with licensing issues when you do that!

  • Fail gracefully when it’s not possible to import them and let the user install them. For example:

    try:import appdirs

    except importError:
    raise importError(‘this package requires “appdirs” to be installed. ‘
    ‘Install it first: “pip install appdirs”.’)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646404.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号