Package python scripts as exe executable files-Example of pyinstaller and cx_freeze

Source: Internet
Author: User

This document describes how to use cx_freeze and pyinstaller to package python scripts as exe files.

Wxapp. py, read_file.py, setup. py

 (self, parent=None, title=== wx.Button(panel, -1, = wx.Button(panel, -1, ==wx.ALL, border=20=wx.ALL, border=20==wx.ALL |= getattr(sys, == os.path.dirname(= os.path.join(path, , == App(1
= line 
 cx_Freeze = {: 2: [= sys.platform == = = [Executable(script========= {=executables)

 

Open cmd to enter the code directory, and enter:

a = Analysis([=[======os.path.join(, ======, r, =)

Open cmd, switch to the pyinstaller directory, and enter the following command:

Python pyinstaller. py path_of_spec (PS: replace path_of_spec with the absolute path of your stored wxapp. spec. You can drag it to cmd to get the path.

I used upx for compression here, or you can skip it. For details, refer to the official website.

After the execution is complete, the wxapp folder is generated. wxapp/dist/distridemo.exe and read_file.py are the files you need.

 

Now, the two packaging methods cx_freeze and pyinstaller have been introduced. I personally prefer pyinstaller, strong customization, automatic search module dependency, the ability to generate separate exe files, detailed official documentation, disadvantages do not support py3.x, but now most of the world is py2.x...

I believe that pyinstaller will follow up shortly when py3.x becomes popular.

 

 

January 23, 2014 20:03:36 update

For pyinstaller usage updates, I read the instructions on the official website again today. For the spec file, I can use a tool to automatically generate one. The command is as follows:

pyi-makespec webapp.py file_read.py

This will generate a wxapp. the spec file can be modified on the basis of this file. Here I only mention a few things to note. In the EXE option, exclude_binaries controls whether to package it into a separate exe file, note that if your software needs to read and write a configuration file, and the configuration file is in the same directory as the app, in your py file, you need to reference the path of this configuration file as follows: BASEDIR = OS. path. dirname (_ file _) to obtain the configuration file, and then use CONFIG_PATH = OS. path. join (BASEDIR, 'config. ini ') to specify the path of the configuration file. nothing else to pay attention

After modifying the spec file, you can use the following command to generate the exe file:

pyi-build wxapp.spec --upx-dir=dir_path_of_upx

 

By: msccreater

Reprinted please indicate the source: http://www.cnblogs.com/msccreater/p/3530250.html

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.