python pip 为 entry_points 配置 python 可执行文件

标签 python setuptools distutils

我有一个要在本地构建以在嵌入式环境中使用的包。

我正在尝试自动生成一个控制台脚本,所以我在 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 解释器,因为它与构建系统中的解释器不同。但无论我尝试什么,它都会一直设置为本地解释器。

我尝试了几个选项,例如:

  1. 在 setup.py 的 shebang header 中设置解释器
  2. 在 setup.py 中设置 sys.executable
  3. 使用 options={'build_scripts': {'executable': 'bin/custom_python'}}
  4. 使用 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/

相关文章:

python - 如何在 Dash Plotly 中将 Long_callback 与多页应用程序一起使用?

python - 如何修复 Django/python free() : invalid pointer?

python - 如何使用 Popen.communicate(在 Linux 上)传递击键(ALT+TAB)?

python - setup.py 中 extras_require 的依赖链接

python - setup.py 没有看到我的 requirements.txt

python - 将简单的 Python 模块移植到 Cython

python - scipy.sparse 默认值

python - 如何制作特定于平台的 Python 包?

python - Setuptools 不为 entry_points 传递参数

python - pip 10 和 apt : how to avoid "Cannot uninstall X" errors for distutils packages