Use PyInstaller to convert a Python program file to an executable program file,

Source: Internet
Author: User
Tags windows support

Use PyInstaller to convert a Python program file to an executable program file,

Use PyInstall in Windows to convert a py file to an exe Executable File
The py file is hard to be written. To create an exe file, you first chose to use py2exe. The resulting exe encountered two problems,
1. print Information in The py program, which is not displayed on the screen after the tool is executed in cmd;
2. Call the dll interface. When the py file is executed, it is blocked and waited. When the exe file is executed in cmd, the tool Returns quickly and the interface is still running, which is very strange.
I couldn't find a solution at the moment, so I had to abandon it. I found pyinstall on the Internet and tried it. I felt more powerful...
Before installing PyInstaller, make sure that pywin32 is installed first.
: Http://nchc.dl.sourceforge.net/project/pywin32/pywin32/Build%20218/pywin32-218.win32-py2.7.exe
 
1. Install PyInstaller
1.: http://www.pyinstaller.org/wiki
2. Latest Version: PyInstaller 2.0
3. Directly decompress the package to the desired path.
 
Ii. PyInstaller Configuration
1. Write the py program in advance
2. Run the following command in the command line:

Python Makespec.py --console --onefile NotePad\notepad.py

Error:

Configfile is missing or unreadable. Please run Configure.py before building

3. Execute the following command in the 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,: http://sourceforge.net/projects/pywin32/files/pywin32/Build%20217/
 
Iii. Use PyInstaller
PyInstaller is relatively simple to use. Run the following command in cmd to enter the decompressed directory:
python pyinstaller.py [opts] yourprogram.py

4. Main options include:
-F,-onefile is packaged into an exe file
-D,-onedir: create a directory that contains the exe file, but will depend on many files (default option)
-C,-console,-now.wed use the console, no interface (default)
-W,-javaswed,-noconsole use window, no console

5. Notes
Before conversion, ensure that the py program can pass normally;
If any errors occur during the conversion process, use search engine to search for them.


Install pyinstaller in Linux to package the py file to generate an executable file
1. Installation and Use Process

1. First install easy_install for the system. If installed, skip this step.
Go to pypi official site https://pypi.python.org/pypi/setuptools to download the latest version

2. Download pyinstaller from the official website. The latest version is 2.1.
(1) web site http://www.pyinstaller.org/

3. Unpack the package to the source code 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 to be packaged, such as test. py, to the current directory.

5. generate an executable file
Cd to the pyinstaller directory and run

python pyinstaller.py test.py

Ii. Possible Problems

1. User Permissions
Running pyinstaller directly under the root user reports the error "cannot run pyinstaller as user root "...
Therefore, you need to add another user and add read and write permissions to the directory where pyinstaller is located and all parent directories to avoid reporting 'mkdir' permission denied...

2. the python lib dynamic library cannot be found.
After su switches to the new user,
Python dynamic library not found in pyinstaller Error

raise IOError("Python library not found!")IOError: Python library not 

Run python -- version to check the current version and find whether the libpython *. *. so file of the corresponding version is available in/usr/local/lib,
If yes, skip this step. If no, reinstall python. You must add the -- enable-shared parameter to the python installation configuration to generate the corresponding dynamic link library, for example:

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

I have updated the python version in my environment. As a result, the library file in/usr/lib is not the latest version. 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

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.