我需要一个独立的python解释器/编译器!

2024-04-26 07:08:43 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我需要一个python编译器(从.py或.pyw到.exe)。在

我遇到的只有:

-cx_冻结(不起作用)

-py2exe(太复杂了)

编辑: 上面的两个程序都很复杂(对我来说),因为你必须制作所有这些设置文件,然后输入一堆参数和命令来让它们工作,我发现了一个叫做gui2的东西exe.py文件但是我似乎无法正确加载。。。有什么想法吗?在

所以我要找的是一个不需要通过python命令行运行的程序。最好是一个独立的程序,您只需选择文件并选择输出(.exe)并单击“转换”。没什么太复杂的,因为我刚开始。在

我之所以要这样做,是因为我有一个程序,我的朋友想看看,但他不想下载python来查看它。我也不希望他能够改变源代码。在

有什么想法吗?在


Tags: 文件命令行py命令程序编辑参数编译器
3条回答

一个选择可能是使用IronPython。IronPython是另一种面向.NET的python方言,与MS Visual Studio配合使用非常容易。在

py2exe-Python到Windows EXE py2exe将Python程序转换为独立的Windows可执行文件,用户无需安装Python即可运行这些程序。请注意,这不是本机代码编译器-您的代码仍会被解释。py2exe只提供所有必要的部分,这样当最终用户双击可执行文件时,Python解释器就会启动来解释代码。py2exe是在Mozilla公共许可下发布的

Pyinstallet可能会有帮助。。。在

但是py2exe并不复杂。。。在

看看这个py2exe示例设置(从这里开始,但是它是意大利语,所以我翻译了它http://bancaldo.wordpress.com/2010/05/13/python-py2exe-setup-py-sample/

#!/usr/bin/python

from distutils.core import setup
import py2exe, sys, wx, os

# Se eseguito senza argomenti, crea l'exe in quiet mode.
# If executed without args, it makes the exe in quiet mode
if len(sys.argv) == 1:
    sys.argv.append("py2exe")
    sys.argv.append("-q")

class FileBrowser(wx.FileDialog):
    def __init__(self):
        wildcard = "Python files (*.py)|*.py|" \
            "Tutti i files (*.*)|*.*"
        dialog = wx.FileDialog(None, "Choose the file", os.getcwd(),
            "", wildcard, wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            print(dialog.GetPath())
        self.file = dialog.GetPath()
        self.fin = open(self.file, 'r')
        dialog.Destroy()

class Target:
    def __init__(self, **kw):
        self.__dict__.update(kw)
        # info di versione
        self.version = "1.0.0"
        self.company_name = "Bancaldo TM"
        self.copyright = "no copyright"
        self.name = "py2exe sample files"

manifest_template = '''
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
     type='win32'
     name='Microsoft.VC90.CRT'
     version='9.0.21022.8'
     processorArchitecture='*'
     publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*" />
    </dependentAssembly>
  </dependency>
</assembly>
'''
# File Browser
app = wx.PySimpleApp()
fb = FileBrowser()
# Assegno il nome all'eseguibile di uscita
# Give the name at the exe file being created
textentry = wx.TextEntryDialog(None, "name file EXE?",'','')
if textentry.ShowModal() == wx.ID_OK:
    destname = textentry.GetValue()

RT_MANIFEST = 24

test_wx = Target(
    description = "A GUI app",
    script = fb.file,     # programma sorgente dal quale creiamo l'exe
                          # source from wich we create the exe
    other_resources = [(RT_MANIFEST, 1, manifest_template % dict(prog="tried"))],
    icon_resources = [(1, "py.ico")],
#    dest_base = "prova_banco") # Nome file di destinazione
                                #Name Destination file
    dest_base = destname) # Nome file di destinazione

setup(
    data_files=["py.ico"],
    options = {"py2exe": {"compressed": 1,
                          "optimize": 2,
                          "ascii": 1,
                          "bundle_files": 1}},
    zipfile = None,
    windows = [test_wx],
    )

它还包括一个小图形界面,可以帮助您选择文件;)

编辑:

这是一个简单的示例,可能更有用:)

^{pr2}$

分步教程:

1-创建一个.py文件,命名为,例如'你好.py'没有图形用户界面 2-做一个设置.py文件

from distutils.core import setup
import py2exe

setup(console=['hello.py'])

注意使用“console”而不是“windows”,因为您没有gui

然后,把你的你好.py文件和你的设置.py然后打开cmd,到达正确的目录(通常是C:\python2x),键入:

python setup.py py2exe

你的exe文件将在dist目录中。如果缺少一些.dll,只需下载它并放入python目录。在

一旦你的程序变得更复杂,它可能需要其他指令;看看其他2条设置.py我贴的样品。 希望能帮上忙

相关问题 更多 >