Package the python program with pyinstaller or virtualenv


Running environment: CentOS6.5_x64

Python version: 2.6

Package with pyinstaller

pyinstaller can package the python program into a binary file, which can be executed in an environment without python (but with the associated underlying libc and so files). pyinstaller supports packaging the python program into a single file. All it does is convert the text to base 2, which does not speed up the python program.

Install pyinstaller

Official site: http: / / www pyinstaller. org /

Installation via pip:

pip install pyinstaller

Install through source code:

python setup.py install

Packaging application

Add the -F parameter to package the program into a separate file:

pyinstaller -F test1.py

Pack with virtualenv

virtualenv is used to create an “isolated” Python environment for each application. Using virtualenv to manage python applications can avoid problems such as library conflicts. Also, virtualenv doesn’t speed up python, all it does is isolate the environment and make it easy to deploy.

Here’s an example:

1. Install virtualenv

pip install virtualenv

2. Create a virtual environment

virtualenv -p /usr/bin/python2.6 py26env --no-site-packages

3. Start the virtual environment

source py26env/bin/activate

4. Install the necessary python libraries

pip install  ...

5, after writing the code to normally start the program program.

Ok, that’s all, I hope it helped you.

conclusion