我需要一个独立的python解释器/编译器! [英] I need a stand alone python interpreter/compiler!

查看:236
本文介绍了我需要一个独立的python解释器/编译器!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我遇到的只有:



- cx_freeze strong>



- py2exe(太复杂)


上面的两个程序都是复杂的(对我来说),因为你必须做所有这些设置文件,并键入一堆参数和命令,让他们工作,我发现了一个名为gui2exe .py然而我似乎没有得到它正确加载...任何想法?



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



我想要的原因是因为我有一个程序,我的朋友想看看,但他不想下载python为了查看它。



任何想法?

解决方案

Pyinstallet可能会帮助...



但是py2exe不复杂...



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

 #!/ usr / bin / python 

来自distutils.core import setup
import py2exe,sys,wx,os

#Se eseguito senza argomenti,crea l'exe in quiet mode。
#如果没有args执行,它使安全模式下的exe
如果len(sys.argv)== 1:
sys.argv.append(py2exe)
sys.argv.append( - q)

class FileBrowser(wx.FileDialog):
def __init __(self):
wildcard =Python文件)| * .py | \
Tutti i files(*。*)| *。*
dialog = wx.FileDialog(无,选择文件,os.getcwd(),
,wildcard,wx.OPEN)
如果dialog.ShowModal()== wx.ID_OK:
print(dialog.GetPath())
self.file = dialog.GetPath $ b self.fin = open(self.file,'r')
dialog.Destroy()

目标:
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示例文件

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>
< / secure>
< / 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>
'''
#文件浏览器
app = wx.PySimpleApp()
fb = FileBrowser()
#Assegno il nome all'eseguibile di uscita
#在正在创建的exe文件中给出名称
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目标文件
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] ,

它包含一个小的图形界面帮助你选择文件; )



编辑:



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

  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,

STEP BY STEP指南:



1 - 创建一个.py文件,命名它,例如'hello.py',没有GUI
2- make a setup.py file



 来自distutils.core import setup 
import py2exe

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

注意使用'console'而不是'windows'不是gui



那么,将你的hello.py文件和你的setup.py文件移动到Python目录中;然后打开cmd,一旦你到达正确的目录(通常是C:\python2x),输入:

  python setup.py py2exe 

您的exe文件将在dist目录中。如果一些.dll丢失,只需下载它,并放在python目录。



一旦你的程序会更复杂,可能需要其他说明;看看其他2 setup.py示例我已经发布。
希望这个帮助


Ok so i am in need of a python compiler (from .py or .pyw to .exe).

the only ones i have come across are:

- cx_freeze (doesnt work)

- py2exe (way too complicated)

EDIT: both of the programs above are complicated (to me) because you have to make all these setup files, and type in a bunch of parameters and commands to get them to work,i found something called gui2exe.py however i cant seem to get it to load correctly... any thoughts?

So what i was looking for was a program that you do not have to run through the python command line. Prefereably a stand alone program, that you can just select the file and select the output (.exe) and click convert. Nothing too complicated as i am just starting out.

The reason i want this is because i have a program that my friend wanted to take a look at but he doesnt want to download python in order to view it. Also i dont want him to be able to change the source code.

Any Ideas?

解决方案

Pyinstallet might help...

however py2exe is not complicated...

take a look at this py2exe sample setup (from here, but it's italian, so i translated it 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],
    )

it inclused also a small graphic interface wich help you on choose the file ;)

EDIT:

this is a simpler sample, maybe it's more useful :)

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, 
)

STEP BY STEP TUTORIAL:

1-create a .py file, naming it, for example, 'hello.py', that has not a GUI 2- make a setup.py file

from distutils.core import setup
import py2exe

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

notice the use of 'console' instead of 'windows', 'cause you have not a gui

then, move your hello.py file and your setup.py file in Python directory; then open the cmd, and once you've arrived at the correct directory (usually C:\python2x), type:

python setup.py py2exe

you're exe file will be in the dist directory. if some .dll are missing, simply download it and place in python directory.

once your program will be more complicated, it may require other instructions; look at the other 2 setup.py samples i've posted. hope this help

这篇关于我需要一个独立的python解释器/编译器!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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