Python compiled into Exe__python

Source: Internet
Author: User
Python's compilation has many benefits, including improving running speed, code secrecy

Mode 1: Compiled into a pyc file (binary file)

Speed has improved. One of my code changed from 150s to 130s. How to: Open cmd, enter the directory of the py file, enter the following command
python3-m py filename
Python3-o-M py_compile py filename #这个也可以
When finished, a __pycache__ folder appears in the current directory, and the compiled binaries are pyc.

Mode 2: Compiled into EXE file
First, install Pyinstaller
Command:
PIP3 Install Pyinstaller
Second, after the installation is completed, start to use. Enter the directory where the py file you want to compile
Pyinstaller./py filename #效果是有一堆的文件在dist文件夹下
If you want to compile into a file:
Pyinstaller--console--onefile./py filename #在dist文件夹下只生成一个exe文件.

First run, may appear failed to create process, this is PIP3 bug, the path of the space can not be properly identified
Solve:
Into the C:\Program files\python\3.5\scripts, you can see that there is a pyinstaller-script.py and Pyinstaller.exe
The text editor opens the pyinstaller-script.py. The first line of code declaration is like this
#!c:\program Files\python\3.5\python3.exe
Add a quotation mark into: #! " C:\Program Files\python\3.5\python3.exe "
Run the compile command again.

At the speed of running,. exe and. PYc. But are greater than the py file. EXE file compatibility better put,. PYC requires that the computer be installed with the same Python version as at compile time. (. PYc is very fast to build)

Question Answer:
1. Compiled into PYC, it will also appear. No _path_ attribute error
"Error while finding spec for ' fibo.py ' (: ' Module ' object has no attribute ' path ')"
This is because at compile time, you should not use the
Python3-m kill2next.py #kill2next是文件名
. py indicates that the module (PY) is in the package Kill2next
Right way:
Python3-m Kill2next #不要带后缀

2.exe compilation failed:
Unicodedecodeerror: "GBK" codec can t decode byte 0xaa in position 160:illegal multibyte sequence
Solve:
Change the file name into English



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.