Use Pyinstaller to convert a Python program file to an executable file _python

Source: Internet
Author: User
Tags parent directory win32 windows support

Pyinstall to convert a py file to an EXE executable file under Windows
finally write the py file, want to make EXE file, the beginning of the choice with Py2exe, the results of the EXE encountered two problems,
1. The information of the print in the PY program, the execution of tool in CMD does not appear on the screen;
2. Call DLL interface, the execution of the py file is blocked waiting, the result of the exe in cmd execution, tool soon returned, the interface is still running, very strange
Unable to find a solution, helpless discard, in the online find Pyinstall, try, feel more powerful ...
Before installing Pyinstaller, you need to verify that Pywin32 is installed first
Download Address: Http://nchc.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win32-py2.7.exe

First, Pyinstaller installation
1. Download Address: Http://www.pyinstaller.org/wiki
2. Latest Version: Pyinstaller 2.0
3. Direct "decompression" can be used after decompression to the path you want him to be

Second, Pyinstaller configuration
1. Write down the PY procedure in advance
2. Execute at command line:

Python makespec.py--console--onefile notepad\notepad.py

Error:

ConfigFile is missing or unreadable. Please run configure.py before building

3. Execute at command line:

configure.py

Error:

Python 2.6+ on Windows support needs pywin32,Please install http://sourceforge.net/projects/pywin32/

4. Install the latest version of Pywin32-217.win32-py2.7.exe, download the address: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/

Iii. Use of Pyinstaller
the use of Pyinstaller is relatively simple, under CMD into the extracted directory, execute the following command:
Python pyinstaller.py [opts] yourprogram.py

Iv. major options include:
-F,-onefile packaged into an EXE file
-D,-onedir creates a directory that contains EXE files, but relies on a number of files (default option)
-C,-console,-nowindowed use console, no interface (default)
-W,-windowed,-noconsole using Windows, no console

V. Matters of attention
Make sure that the PY program passes correctly before you convert;
If there are any errors in the conversion process, use search engine search to solve.


Linux install Pyinstaller used to package the Py file to generate an executable file
I. Installation and use Process

1. First the system to install a Easy_install, if installed can skip this step
To the PyPI official website https://pypi.python.org/pypi/setuptools to download the latest version

2. Official online download Pyinstaller, the current latest version is 2.1
(1) Website http://www.pyinstaller.org/

3. Unpack into the source directory
(1)

TAR-ZXVF pyinstaller_2.1.tar.gz

(2)

CD pyinstaller-2.1

Run

Python setup.py Install

4. Copy the py file
Copy the py file you want to package, such as test.py, to the current directory

5. Generate executable Files
CD to Pyinstaller directory, performing

Python pyinstaller.py test.py

Ii. problems that may be encountered

1. User Rights
Run directly under root user Pyinstaller will be the error "cannot run Pyinstaller as user root" ...
So you need to add another user, and give the user to the directory where Pyinstaller and all the parent directory added read and write permissions, to avoid running after the ' mkdir ' permission denied ...

2. Python lib Dynamic library not found
When SU switches to the new user,
Pyinstaller error can't find Python dynamic library

Raise IOError ("Python Library not found!")
Ioerror:python Library not 

Execute the Python--version view the current version and look for the corresponding version of the libpython*.*.so file under/usr/local/lib.
If you skip this step, and if you do not need to reinstall Python, you must add the--enable-shared parameter in the Python installation configuration to generate the corresponding dynamic link library, such as:

#./configure--enable-shared--prefix=/usr/local
#make
#make Install

My environment has updated the Python version, resulting in/usr/lib is not the latest version of the library file, you need to copy the new version to the corresponding/usr/lib directory, note that there are two files:

#cp libpython*.so/usr/lib/
#ln-S/usr/lib/libpython*.so.1.0/usr/lib/libpython*.so

Related Article

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.