Python 终于打包成功了,MLBD

每次NN做了点东西,就在那边炫耀,而且把代码打包,不让我看。

只要我做点什么东西,他就会凑过来看。

我也想打包一下,可是不知道是环境还是啥的,总是失败。

今天他又在炫耀,其实他做的的那东西,就那样,但是获得了赞扬一片。

哥辛辛苦苦培训出来的哪些人,都不感恩下哥。哎!

对待这种人,哥决定已牙还牙,自己弄。

开始找了几个网站,实验不成功,最后一个终于成了。

以后哥也可以隐藏代码了,不在那么分享了,成了徒弟,饿死了师傅。

都什么世道。

 

http://blog.csdn.net/livecoldsun/article/details/27975787

最近遇到个简单的小问题,要想将编写的python代码在别人的电脑上运行,由于没有配置python的环境,这就有了困难。搜索学习了下,借助一定的工具可以将python程序的.py文件打包为exe文件,当然有多种方法,本文介绍的 方法(pyinstaller + pywin32)经亲测可行。步骤如下,供参考:

1、下载pyinstaller并解压到本地,下载地址:http://sourceforge.net/projects/pyinstaller/?source=dlp  将我用的版本传到网上:http://download.csdn.net/detail/zhangyalin1992/7433193,供参考下载;

2、下载pywin32相应版本并安装。 下载地址:http://sourceforge.net/projects/pywin32/files/pywin32/  这里我win7 64 位系统,python2.7.5 所用的版本如下:http://download.csdn.net/detail/zhangyalin1992/7433203

3、工具准备完毕,下面就可以进行py文件的打包了,将你的py文件拷贝到pyinstaller解压后的文件夹下;

4、在该文件夹,按住shift键同时右击鼠标,选择“在此处打开命令窗口”,运行cmd,在cmd输入如下内容(其中hello.py是你的py文件,可用其他名字):

    python pyinstaller.py -F hello.py

5、等待cmd执行完毕,如果成功,会看到该目录下出现hello的文件夹,其中的dist子目录会包含hello.exe的文件,就是我们所要的文件

 

 

源文档 <http://blog.csdn.net/livecoldsun/article/details/27975787>

 

 那些打包成一个文件,或者将文件的图标修改等等操作都和这个 [opts] 有关系.

 

         下面举些例子(客官一看便知,以 pyinstaller-2.0为例子,1.5通用):

               ① 打包成一个文件:

                       python pyinstaller.py --onefile  yourprogram.py

               ②,修改exe的图标(D:\BabyWandH\src\faviconw.ico为图标的存放路径):

                        python pyinstaller.py--onefile  --icon=D:\BabyWandH\src\faviconw.ico  yourprogram.py

 

            [opts]的一些说明(具体可以看pyinstaller官网http://www.pyinstaller.org/expor ...talling-pyinstaller):

 

源文档 <http://cloudbbs.org/forum.php?mod=viewthread&tid=13537>

 

 

http://cloudbbs.org/forum.php?mod=viewthread&tid=13537

 

我经常用python写些脚本什么的,有时候脚本写完以后,每次运行都得在IDE打开在运行,很麻烦,所以经常将python编译成exe.SO...有了一点经验,在这和大家分享一下。

    python 打包成exe 主要有两种,一种是py2exe,另一种便是pyInstaller,之前我是用py2exe的,但是我后来发现py2exe存在问题:1,打包好的 exe只能在相同的系统下运行,比如你在XP系统用py2exe打包好的exe只能在XP上运行,在win7上肯定有问题,而且也是存在在别的XP机子上 也可能不能运行,因为一些别的机子可能会缺少dll文件什么的,作者我当时之所以抛弃py2exe 也是因为这个原因;2,打包的文件也需要打包同exe下的dll,和一些库的压缩包,不然exe根本跑不起来

 

 

 

    所以作者强烈建议大家在python打包的话使用pyInstaller,在这我主要同大家分享pyInstaller的打包方法.

 

    话不多说,开始.....

 

 

    pyInstaller是一款用于将pyhon程序打包成exe文件的工具,pyInstaller不是一个python的包, 只需要把pyInstaller的文件下载下来放到任意为止都可以,也就是说pyInstaller相当于独立出来专门干打包python的工具,这货是 工具不是库,也不是包...

    

    1.下载安装pyinstaller,下载网址:http://www.pyinstaller.org/去下载,然后解压到任意目录.(注意:在pyinstaller2.0之前的版本要是移动这个文件夹的话,需要改一些配置,不然pyinstaller会因为你的移动不能使用.这个和后面的配置环境有关.pyinstaller2.0的版本就没有限制.)

 

    2.编译配置环境(以解压到F:盘为例子)

       ① pyinstaller-2.0的方法:

            打开cmd cd进入解压后的目录下的sorce下,即:cd  F:\pyinstaller-2.0\source

            运行 python ./waf configurebuild install

            *(可能需要安装pywin32.下载并安装即可,重新运行命令即可)

 

 

 

       ②  pyinstaller-1.5

             打开cmd cd进入pyinstaller解压目录,cd  F:\pyinstaller-1.5                 

             运行  python Configure.py

             *(可能需要安装pywin32.下载并安装即可,重新运行命令即可)

             结果提示保存在config.dat文件中。其中config.dat文件存放在pyinstaller的根目录。

 

 

    3. 将自己写的py程序打包exe

         ① pyinstaller-2.0的方法:

              将自己写的py文件(HelloWorld.py)拷贝到pyinstaller解压目录下,

              打开cmd cd进入解压后的目录下,即:cd  F:\pyinstaller-2.0\

              运行命令 pythonpyinstaller.py [opts] yourprogram.py

              在此处则是运行:pythonpyinstaller.py [opts] HelloWorld.py

              在目录下会生成一个helloworld的文件夹,里面存放HelloWorld.spec文件,;两个文件夹(distbuildi),可以运行的exe则放在/dist/yourprogram

 

 

 

         ②  pyinstaller-1.5

               将自己写的py文件(HelloWorld.py)拷贝到pyinstaller解压目录下,

               打开cmd cd进入解压后的目录下,即:cd  F:\pyinstaller-1.5\

               pyinstaller-1.5pyinstaller-2.0 的区别来了。

               pyinstaller-1.5 中你先需要生成spec文件,然后通过spec文件在生成exe文件,而 pyinstaller-2.0 在执行命令(请看上面)后会同时吧exespec文件都生成出来了

               所以在pyinstaller-1.5 你得先生成spec文件:

               pythonMakespec.py  [opts] yourprogram.py

                  运行命令: python Makespec.py  [opts]HelloWorld.py

               此时在此目录下生成的HelloWorld文件夹,文件夹下有一个 HelloWorld.spec文件,将文件在拷贝到目录(F:\pyinstaller-1.5\)下

                  运行命令:python Build.py HelloWorld.spec

 

    4.你会发现按照上面的方法在/yourprogram/dist/yourprogram下除了需要的exe文件,也存在很多dll文件,然后你会开始抱怨作者我坑爹了吧....

       哈哈,如果你这么发现了,说明,你已经完成用最基础的pyinstaller打包了,关于如何pyinstaller请往下看:

 

       不管是pyinstaller-1.5还是pyinstaller-2.0,要想打包成一个文件,或者将文件的图标修改等等操作,这些都与你在运行命令时有关系,还记得命令是什么吗?

          pyinstaller-2.0 是:

              python pyinstaller.py [opts]yourprogram.py

          pyinstaller-1.5 是:

              pythonMakespec.py  [opts] yourprogram.py

 

         那些打包成一个文件,或者将文件的图标修改等等操作都和这个 [opts] 有关系.

 

         下面举些例子(客官一看便知,以 pyinstaller-2.0为例子,1.5通用):

               ① 打包成一个文件:

                       python pyinstaller.py --onefile  yourprogram.py

               ②,修改exe的图标(D:\BabyWandH\src\faviconw.ico为图标的存放路径):

                        python pyinstaller.py--onefile  --icon=D:\BabyWandH\src\faviconw.ico  yourprogram.py

 

            [opts]的一些说明(具体可以看pyinstaller官网http://www.pyinstaller.org/expor ...talling-pyinstaller):

 

源文档 <http://cloudbbs.org/forum.php?mod=viewthread&tid=13537>

 

发布了162 篇原创文章 · 获赞 33 · 访问量 43万+
展开阅读全文

pyinstaller如何打包含有dll的.py文件?

10-11

命令:pyinstaller test.spec 执行:test.exe 出错:E:\python\project\lbmWebS\lib\testapi.dll could not be extracted! 打包的warn文件 missing module named unicodedata.ucd_3_2_0 - imported by unicodedata, stringprep, encodings.idna missing module named _warnings.warn_explicit - imported by _warnings, warnings missing module named _warnings.filters - imported by _warnings, warnings missing module named _warnings.once_registry - imported by _warnings, warnings missing module named _warnings.default_action - imported by _warnings, warnings missing module named _warnings.warn - imported by _warnings, warnings missing module named _subprocess.STD_OUTPUT_HANDLE - imported by _subprocess, subprocess missing module named _subprocess.CREATE_NEW_PROCESS_GROUP - imported by _subprocess, subprocess missing module named _subprocess.STD_INPUT_HANDLE - imported by _subprocess, subprocess missing module named _subprocess.STARTF_USESHOWWINDOW - imported by _subprocess, subprocess missing module named _subprocess.CREATE_NEW_CONSOLE - imported by _subprocess, subprocess missing module named _subprocess.STD_ERROR_HANDLE - imported by _subprocess, subprocess missing module named _subprocess.STARTF_USESTDHANDLES - imported by _subprocess, subprocess missing module named _subprocess.SW_HIDE - imported by _subprocess, subprocess missing module named cPickle.loads - imported by cPickle, collections missing module named cPickle.dumps - imported by cPickle, collections missing module named thread.get_ident - imported by thread, collections missing module named thread._local - imported by thread, threading missing module named thread.stack_size - imported by thread, threading missing module named thread.allocate_lock - imported by thread, _strptime missing module named itertools.chain - imported by itertools, heapq, collections missing module named itertools.starmap - imported by itertools, collections missing module named itertools.repeat - imported by itertools, heapq, collections missing module named itertools.imap - imported by itertools, heapq missing module named itertools.tee - imported by itertools, heapq missing module named itertools.izip - imported by itertools, heapq missing module named itertools.count - imported by itertools, heapq missing module named itertools.islice - imported by itertools, repr, heapq missing module named operator.itemgetter - imported by operator, collections, heapq missing module named operator.attrgetter - imported by operator, inspect missing module named _collections.deque - imported by _collections, collections missing module named _collections.defaultdict - imported by _collections, collections missing module named _weakref.ref - imported by _weakref, _weakrefset, weakref missing module named _weakref.ReferenceType - imported by _weakref, weakref missing module named _weakref.proxy - imported by _weakref, weakref missing module named _weakref.getweakrefs - imported by _weakref, weakref missing module named _weakref.getweakrefcount - imported by _weakref, weakref missing module named _weakref.ProxyType - imported by _weakref, weakref missing module named _weakref.CallableProxyType - imported by _weakref, weakref missing module named time.time - imported by time, threading missing module named time.sleep - imported by time, threading missing module named datetime.date - imported by datetime, _strptime missing module named errno.ENOENT - imported by errno, gettext missing module named _functools.partial - imported by _functools, functools missing module named _functools.reduce - imported by _functools, functools missing module named copy.deepcopy - imported by copy, weakref missing module named exceptions.ReferenceError - imported by exceptions, weakref missing module named binascii.hexlify - imported by binascii, random missing module named math.sin - imported by math, random missing module named math.sqrt - imported by math, random missing module named math.cos - imported by math, random missing module named math.acos - imported by math, random missing module named math.ceil - imported by math, random missing module named math.exp - imported by math, random missing module named math.log - imported by math, random missing module named math.e - imported by math, random missing module named math.pi - imported by math, random missing module named readline - imported by cmd, pdb missing module named errno.EINVAL - imported by errno, StringIO missing module named cStringIO.StringIO - imported by cStringIO, gettext, pickle, pprint, shlex, tempfile, encodings.uu_codec, quopri, encodings.quopri_codec missing module named binascii.b2a_qp - imported by binascii, quopri missing module named binascii.a2b_qp - imported by binascii, quopri missing module named binascii.a2b_uu - imported by binascii, encodings.uu_codec missing module named binascii.b2a_uu - imported by binascii, encodings.uu_codec missing module named 'org.python'.PyStringMap - imported by 'org.python', pickle missing module named 'org.python' - imported by pickle missing module named struct.calcsize - imported by struct, ctypes missing module named _struct.__doc__ - imported by _struct, struct missing module named _struct._clearcache - imported by _struct, struct missing module named fcntl - imported by subprocess, tempfile missing module named threading.RLock - imported by threading, _threading_local missing module named threading.current_thread - imported by threading, _threading_local missing module named os.urandom - imported by os, random missing module named riscosenviron._Environ - imported by riscosenviron, os missing module named riscosenviron - imported by os missing module named riscospath - imported by os missing module named riscos._exit - imported by riscos, os missing module named riscos - imported by os missing module named ce._exit - imported by ce, os missing module named ce - imported by os missing module named _emx_link.link - imported by _emx_link, os missing module named _emx_link - imported by os missing module named os2._exit - imported by os2, os missing module named os2 - imported by os missing module named nt._isdir - imported by nt, ntpath missing module named nt._getfullpathname - imported by nt, ntpath missing module named nt._exit - imported by nt, os missing module named pwd - imported by posixpath missing module named posix._exit - imported by posix, os missing module named posix - imported by os missing module named resource - imported by posix missing module named strop.whitespace - imported by strop, string missing module named strop.maketrans - imported by strop, string missing module named strop.lowercase - imported by strop, string missing module named strop.uppercase - imported by strop, string missing module named org.PyStringMap - imported by org, copy missing module named org - imported by copy missing module named re._compile - imported by re, sre missing module named re.__all__ - imported by re, sre missing module named codecs.mbcs_encode - imported by codecs, encodings.mbcs missing module named codecs.mbcs_decode - imported by codecs, encodings.mbcs missing module named _ctypes._wstring_at_addr - imported by _ctypes, ctypes missing module named _ctypes._string_at_addr - imported by _ctypes, ctypes missing module named _ctypes._cast_addr - imported by _ctypes, ctypes missing module named _ctypes._memset_addr - imported by _ctypes, ctypes missing module named _ctypes._memmove_addr - imported by _ctypes, ctypes missing module named _ctypes.get_last_error - imported by _ctypes, ctypes missing module named _ctypes.set_last_error - imported by _ctypes, ctypes missing module named _ctypes._check_HRESULT - imported by _ctypes, ctypes missing module named _ctypes.set_conversion_mode - imported by _ctypes, ctypes missing module named _ctypes._pointer_type_cache - imported by _ctypes, ctypes missing module named _ctypes.POINTER - imported by _ctypes, ctypes missing module named _ctypes._SimpleCData - imported by _ctypes, ctypes missing module named _ctypes.get_errno - imported by _ctypes, ctypes missing module named _ctypes.set_errno - imported by _ctypes, ctypes missing module named _ctypes.alignment - imported by _ctypes, ctypes missing module named _ctypes.addressof - imported by _ctypes, ctypes missing module named _ctypes.resize - imported by _ctypes, ctypes missing module named _ctypes.byref - imported by _ctypes, ctypes missing module named _ctypes.sizeof - imported by _ctypes, ctypes missing module named _ctypes.dlopen - imported by _ctypes, ctypes missing module named _ctypes.FUNCFLAG_STDCALL - imported by _ctypes, ctypes missing module named _ctypes.LoadLibrary - imported by _ctypes, ctypes missing module named _ctypes.FUNCFLAG_USE_ERRNO - imported by _ctypes, ctypes missing module named _ctypes.FUNCFLAG_USE_LASTERROR - imported by _ctypes, ctypes missing module named _ctypes.FUNCFLAG_PYTHONAPI - imported by _ctypes, ctypes missing module named _ctypes.FUNCFLAG_CDECL - imported by _ctypes, ctypes missing module named _ctypes.FormatError - imported by _ctypes, ctypes missing module named _ctypes.ArgumentError - imported by _ctypes, ctypes missing module named _ctypes.RTLD_LOCAL - imported by _ctypes, ctypes missing module named _ctypes.RTLD_GLOBAL - imported by _ctypes, ctypes missing module named _ctypes.__version__ - imported by _ctypes, ctypes missing module named _ctypes.CFuncPtr - imported by _ctypes, ctypes missing module named _ctypes._Pointer - imported by _ctypes, ctypes missing module named _ctypes.Structure - imported by _ctypes, ctypes missing module named _ctypes.Array - imported by _ctypes, ctypes missing module named _ctypes.Union - imported by _ctypes, ctypes 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览