如何使Python脚本成为可执行程序 [英] How to make a Python script an executable program

查看:156
本文介绍了如何使Python脚本成为可执行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要清楚,不仅仅是运行python脚本" 但是要使我的python脚本成为可执行"或可调用"程序 可以在其他编程语言或平台中使用. 也许更像API.

To be clear, not just "run python scripts" But to make my python script a "executable" or "callable" program that can be used in other programming languages or platforms. More like a API maybe.

问题是我在Java中实现了几种算法, 他们得到了numpy和spipy的支持,但其他人希望 在他们的java程序中调用我的python程序.

The thing is I implemented several algorithms in java and they're supported by numpy and spipy, but others want to call my python program in their java program.

然后,numpy和spipy就是问题.他们不能在Java和 jython ...

Then the numpy and spipy are problems. They can't be in java and jython...

是否有一种解决方案,可以使它成为其他人不需要环境而只需要在接受几个参数的情况下运行该程序的可执行程序?

Is there a solution that I can make this an executable program that others don't need the environment but just to run the program with several parameters accepted?

推荐答案

如果只需要使python程序可执行,则可以像这样在顶部添加一行:

If you just need to make the python programs executable, then you can add a line to the top like this:

   #!/usr/bin/python

将/usr/bin/python替换为python的文件路径,可以通过键入

Replace /usr/bin/python with the filepath to python, which can be obtained by typing

    which python 

进入终端,假设您使用的是基于Unix的系统.

into the terminal, assuming you're using a unix-based system.

然后您可以告诉操作系统该程序可以通过以下方式执行

You can then tell the operating system that the program is executable with

    chmod +x nameofprogram

如果Java程序需要的不仅是能够将python部分作为可执行文件运行,还需要更复杂的东西,那么您可能需要向任何人提供更多信息,以便能够为您提供帮助.

If the java programs require something more complicated than just being able to run the python parts as executables, then you'll probably need to provide more information for anyone to be able to help you.

这篇关于如何使Python脚本成为可执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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