Python Packing slip file executable program __python

Source: Internet
Author: User

This two days with Python wrote a gadget, want to do not install Python on the machine to execute, first thought of Pyinstaller.

Pyinstaller packaging programs usually require only one command:

1. Open the CMD console, the directory to switch to the Pyinstaller installation directory, my D:\python\Python36\Scripts directory;

2. Input command:pyinstaller D:\JetBrains\PyCharm\workspace\nginx management tools \main.py -f-w-i f:/picture/1.ico-n admin Tools-P D: \python\python36\lib\site-packages

Description: The red part is to package the main program path;

Optional parameters after the Red section:

-F: Packaged as a single file executable program, without this parameter there will be many other files with executables

-W: Whether it is a window program, not specified, the program runs when there is a console black window

-I: Icons for executable files

-N: Name of the executable file

-P: The search directory to include when packing, generally do not specify the item

Other parameters can be referenced Pyinstaller official documents.

3. If the configuration is no problem, hit the ENTER key, wait for a while to compile the completion. A dist directory is generated in the scripts directory where you can view the compiled executable program, as shown in the following procedure:





In general, this executable file can be run alone. But my program is a little bit more complicated, and my program is a flask-write Web program. Direct operation of the word has been reported template files can not find errors, the template file copied to the same directory does not work. Baidu did not find a solution, and finally Google came up with the solution: in the creation of the Flask App object to add this judgment can:

From flask import Flask
Import sys
import os

app = None
if getattr (sys, ' Frozen ', False):
    template_ folder = Os.path.join (sys.executable, ' ... ', ' templates ')
    Static_folder = Os.path.join (sys.executable, ' ... ', ') Static ')
    app = Flask (__name__, Template_folder=template_folder, Static_folder=static_folder)
else:
    app = Flask (__name__)
Reference Link: https://stackoverflow.com/questions/32149892/flask-application-built-using-pyinstaller-not-rendering-index-html

Next, recompile and copy the template files and executable programs to the same directory and run successfully.





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.