我有一个要在本地构建以在嵌入式环境中使用的包。
我正在尝试自动生成一个控制台脚本,所以我在 entry_points 中使用 console_scripts,如下所示:
setup(...,
entry_points={
'console_scripts': [
'app=x.y:main'
]
},
# Below is added as the other tried methods failed.
options={
'build_scripts': {
'executable': '/bin/custom_python',
},
}
)
我正在尝试设置 entry_point 中使用的 python 解释器,因为它与构建系统中的解释器不同。但无论我尝试什么,它都会一直设置为本地解释器。
我尝试了几个选项,例如:
- 在 setup.py 的 shebang header 中设置解释器
- 在 setup.py 中设置 sys.executable
- 使用 options={'build_scripts': {'executable': 'bin/custom_python'}}
- 使用 pip install --global-option=build --global-option='--executable=/bin/custom_python'
但以上方法均无效。我想知道我是否遗漏了什么?
最佳答案
所以最后我设法做到了。
首先,我必须将以下内容添加到我的设置调用中,这在各种帖子中都有建议:
options={
'build_scripts': {
'executable': '/bin/custom_python',
},
}
现在我像往常一样构建和安装包。就我而言,我创建了一个轮子并安装了它:
python3 setup.py sdist bdist_wheel -d wheels
pip3 install --no-deps -U --prefix $TARGET_INSTALL wheels/mypackage.whl
以上将为创建的脚本使用本地 python 解释器
为了解决这个问题,我运行了以下命令:
python3 setup.py install_scripts -d $TARGET_INSTALL/bin
用“build_scripts”选项中传递的正确脚本替换脚本。
但是我还是想知道有没有办法在用pip安装wheel的时候直接得到正确的解释器?
关于python pip 为 entry_points 配置 python 可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51284961/