如何从python控制台中访问python包元数据? [英] How to access python package metadata from within the python console?

查看:89
本文介绍了如何从python控制台中访问python包元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 distutils.core 构建了一个python软件包,例如通过

If I have built a python package employing distutils.core, e.g. via

setup(
    ext_package="foo",
    author="me",
    version="1.0",
    description="foo package",
    packages=["foo",],
)

所有元数据都放在哪里(目的是什么?),如何从python中访问它。具体而言,在执行

where does all the metadata go (what is it intended for?) and how can I access it from within python. Specifically, how can I access the author information from the python console after doing something like

>>> import foo


推荐答案

访问元数据的一种方法是使用 pip 的问题:

One way to access the metadata is to use pip:

import pip

package = [pckg for pckg in pip.get_installed_distributions() 
            if pckg.project_name == 'package_name'][0]
#  package var will contain some metadata: version, project_name and others.

pkg_resources

from pkg_resources import get_distribution

pkg = get_distribution('package_name')  # also contains a metadata

这篇关于如何从python控制台中访问python包元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆