Objective
Recently wrote a small test program, Python to write up only a short 100 lines, but packaged up without C so easy. Here's a record of my tough "pack and go" process.
Method One: Py2exe
Py2exe is a classic method, why do you say he is classic? Because this thing took a so good name, but only support to python3.4, you this let us keep up with the trend of the tide of the surfers how to pack?
All right, give it up.
Method Two: Pyinstaller
This is a seemingly more reliable method, just need to install with PIP, and then in the Command window in a way to do it. Here I refer to another elder brother's blog (http://blog.csdn.net/mrlevo520/article/details/51840217)
No matter how much, I directly rinsed, start the PIP, open Anaconda Prompt, enter "Pip Install Pyinstaller"
I use Anaconda installed Python3, so naturally use is Anaconda Prompt, here everyone should have no doubt about it:).
The result is regrettable:
Permissionerror: [Winerror 32] Another program is using this file and the process cannot access it.
Helpless I had to surf the internet for help, in this classmate's blog (http://blog.csdn.net/qq_33530388/article/details/68933201) found a solution, the original is the problem of coding. Although the Py3 unified with Utf-8. But the end of the win display with or GBK encoding.
Here's how to fix it:
Find the Compat folder under pip from your Python folder, my F:\python\Anaconda3\Lib\site-packages\pip\compat is right here, there is a __init__.py file, open it, Take the following actions: Return S.decode (' Utf_8 ') to return S.decode (' cp936 ')
OK, try again after the end, see if you can solve it.
Permissionerror: [Winerror 32] Another program is using this file and the process cannot access it. OK, still not ...
But Kung fu is a conscientious, finally in another blog there (http://blog.csdn.net/create115721/article/details/79238696), I found a solution:
Change all the ' utf-8 ' in the __init__.py file to ' GBK '. This solves the problem of coding.
The installation is complete, and the package starts next.
And I forgot the same as I do in the CMD in Windows to operate the classmate please consciously review (http://www.cnblogs.com/kekec/p/3662125.html), I here is directly into the F disk, enter "F:", Then keep the CD to the folder where my code is located.
Final execution command: Pyinstaller work1.py
Results:
So it's done, right? Go to the Dist folder in the directory to open it, run the. exe file, and no problem. But.. We also missed an important detail.
Since we do not add parameters, the Pyinstaller is packaged into a bulk package. The specific parameters are as follows:
Parameters |
Defined |
-F |
Specifies that only one EXE format file is generated after packaging |
-D |
–onedir Create a directory that contains EXE files but relies on many files (default option) |
-C |
–console,–nowindowed using the console, no interface (default) |
-W |
–windowed,–noconsole using Windows, no console |
-P |
Add a search path to find the corresponding library. |
-I. |
Change the icon of the generated program |
so you can use the parameter-F to generate a file, enter: Pyinstaller-f work1.pyThis file can be sent to your friends, open the Happy Happy (Pack B)!
Use Pyinstaller to package Python code (. py) as an executable (. exe) in a WIN10 environment