Shebang线 - 多个允许的口译员按订单

发布于 2025-01-18 06:13:02 字数 422 浏览 3 评论 0原文

我有一个需要Python3.7或以上的脚本。 我有多个具有不同Python版本的系统。所有这些都有Python3.7或Python3.8,但仅仅是“ Python3”也可以是Python3.6。

有没有办法使Shebang系列使用Python3.7或Python3.8?如果没有,则失败。

我尝试了十亿个选择,没有任何可行的方法。我希望有类似的东西:

#!/usr/bin/python3.7 || /usr/bin/python3.8

或者

#!/usr/bin/python3.7
#!/usr/bin/python3.8

让我很难过

是nada ..我也无法搜索它,这有点 默认情况下并在每种设置上安装Python3.7并不是一个选择(这会使生活很棒)。

I've got a script that requires python3.7 or above.
I've got multiple systems each with different python versions. all of them have either python3.7 or python3.8 but just "python3" can also be python3.6.

Is there a way to make a shebang line take either python3.7 or python3.8? and fail if none exist of course.

I tried a billion of options and nothing works. I was hoping for something like:

#!/usr/bin/python3.7 || /usr/bin/python3.8

or

#!/usr/bin/python3.7
#!/usr/bin/python3.8

but nada.. I also couldn't google it up which kinda makes me sad but who knows maybe the answer is there somewhere and I'm just using a bizarre jargon

these are not systems I can change defaults on and installing python3.7 on each such setup is sadly not an option (would make life awesome).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪是无色的血 2025-01-25 06:13:02

Shebang只需要指向实际的可执行文件即可。

可执行文件可以是找到python解释器的合适版本的;例如,请参见长期以来在Windows上流行的py工具,但现在也可以在真实的计算机上提供。其他平台。

最终,某个地方需要在用户的路径上,显然您不会总是控制。如果您针对不老练的用户,则可能考虑以编译后的可执行文件,预包装的Docker映像或类似类似的内容提供代码。

The shebang simply needs to point to an actual executable.

That executable can be one which finds a suitable version of the Python interpreter; see for example the py tool which was popular on Windows for a long time but which is now also being made available on real computers. other platforms.

Ultimately, something somewhere needs to be on the user's PATH, which obviously you will not always have control over. If you are targeting unsophisticated users, perhaps look into providing your code in a compiled executable, a prepackaged Docker image, or something vaguely like that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文