gpt4 book ai didi

python - 更改用于打包的 console_script 入口点解释器

转载 作者:太空狗 更新时间:2023-10-29 17:58:04 26 4
gpt4 key购买 nike

我正在使用众所周知的第三方打包系统打包一些 python 包,但我遇到了入口点创建方式的问题。

当我在我的机器上安装入口点时,入口点将包含一个指向任何 python 解释器的 shebang,如下所示:

/home/me/development/test/setup.py

from setuptools import setup
setup(
entry_points={
"console_scripts": [
'some-entry-point = test:main',
]
}
)

/home/me/.virtualenvs/test/bin/some-entry-point:

#!/home/me/.virtualenvs/test/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'test==1.0.0','console_scripts','some-entry-point'
__requires__ = 'test==1.0.0'
import sys
from pkg_resources import load_entry_point

sys.exit(
load_entry_point('test==1.0.0', 'console_scripts', 'some-entry-point')()
)

如您所见,入口点样板文件包含一个硬编码路径,指向 python 解释器,该路径位于我用来创建第三方包的虚拟环境中。

使用我的第三方打包系统安装这个入口点会导致在机器上安装入口点。但是,由于这种对目标机器上不存在的 python 解释器的硬编码引用,用户必须运行 python/path/to/some-entry-point

shebang 使它变得非常不可移植。 (这当然不是 virtualenv 的设计目标;但我只需要让它在这里更便携一些。)

我不想求助于疯狂的 find/xargs/sed 命令。 (虽然这是我的后备。)

有什么方法可以在 shebang 之后使用 setuptools 标志或配置更改解释器路径?

最佳答案

您可以通过设置“sys.executable”来自定义 console_scripts 的 shebang 行(从 debian bug report 中了解到)。也就是说……

sys.executable = '/bin/custom_python'

setup(
entry_points={
'console_scripts': [
... etc...
]
}
)

更好的方法是在构建时包含“执行”参数...

setup(
entry_points={
'console_scripts': [
... etc...
]
},
options={
'build_scripts': {
'executable': '/bin/custom_python',
},
}
)

关于python - 更改用于打包的 console_script 入口点解释器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17237878/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com