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

dan*_*l11 0 python compiler-construction

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

我遇到的唯一的是:

-cx_freeze(无效)

-py2exe(太复杂了)

编辑:以上 两个程序对我来说都很复杂,因为您必须制作所有这些安装文件,并键入一堆参数和命令才能使它们工作,我发现了一个名为gui2exe.py的东西,但是我似乎无法让它正确加载...有什么想法吗?

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

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

有任何想法吗?

Ant*_*Ant 5

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],
    )
Run Code Online (Sandbox Code Playgroud)

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

编辑:

这是一个简单的示例,也许更有用:)

from distutils.core import setup
import py2exe
setup(
    name = 'AppPyName',
    description = 'Python-based App',
    version = '1.0',
    windows = [{'script': 'Main.pyw'}],
    options = {'py2exe': {'bundle_files': 1,'packages':'encodings','includes': 'cairo, pango, pangocairo, atk, gobject',}},
    data_files=[ 'gui.glade',]
    zipfile = None, 
)
Run Code Online (Sandbox Code Playgroud)

分步教程:

1创建一个.py文件,将其命名为没有GUI的“ hello.py”,例如2。创建setup.py文件

from distutils.core import setup
import py2exe

setup(console=['hello.py'])
Run Code Online (Sandbox Code Playgroud)

注意使用“控制台”而不是“ Windows”,因为您没有GUI

然后,将您的hello.py文件和setup.py文件移动到Python目录中;然后打开cmd,然后到达正确的目录(通常为C:\ python2x),键入:

python setup.py py2exe
Run Code Online (Sandbox Code Playgroud)

您的exe文件将位于dist目录中。如果缺少某些.dll,只需将其下载并放在python目录中。

一旦您的程序变得更加复杂,它可能需要其他说明;看看我发布的其他2个setup.py示例。希望这个帮助