如何使Python脚本成为可执行程序

如何使Python脚本成为可执行程序

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

问题描述

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

To be clear, not just "run python scripts"But to make my python script a "executable" or "callable" programthat 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 andthey're supported by numpy and spipy, but others want tocall my python program in their java program.

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

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

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

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脚本成为可执行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 23:57