访问 python egg 自己的元数据 [英] Accessing python egg's own metadata

查看:51
本文介绍了访问 python egg 自己的元数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 setuptools 生成了一个 python egg,并想在运行时访问它的元数据.我目前正在工作:

I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this:

import pkg_resources
dist = pkg_resources.get_distribution("my_project")
print(dist.version)

但是如果我安装了同一个鸡蛋的多个版本,这可能会错误地工作.如果我同时安装了egg 和开发版本,那么从开发版本运行此代码将获取已安装egg 的版本.

but this would probably work incorrectly if I had multiple versions of the same egg installed. And if I have both installed egg and development version, then running this code from development version would pick up version of the installed egg.

那么,我如何获取我的蛋的元数据,而不是安装在我的系统上的随机匹配的蛋?

So, how do I get metadata for my egg not some random matching egg installed on my system?

推荐答案

我对 Python 也有些陌生,但据我了解:

I am somewhat new to Python as well, but from what I understand:

虽然您可以安装多个版本的同一个"egg(具有相同的名称),但在运行时任何特定代码段只能使用其中一个版本(基于您的发现方法).因此,如果您的 egg 是调用此代码的人,那么它必须已经被选为此代码的 版本的 my_project,并且您将访问您自己的版本.

Although you can install multiple versions of the "same" egg (having the same name), only one of them will be available to any particular piece of code at runtime (based on your discovery method). So if your egg is the one calling this code, it must have already been selected as the version of my_project for this code, and your access will be to your own version.

这篇关于访问 python egg 自己的元数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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