Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PyInstaller Quickstart
- Install PyInstaller from PyPI:
- pip install pyinstaller
- Go to your program’s directory and run:
- pyinstaller yourprogram.py
- This will generate the bundle in a subdirectory called dist.
- PyInstaller bundles a Python application and all its dependencies into a single package. The user can run the packaged app without installing a Python interpreter or any modules. PyInstaller supports Python 2.7 and Python 3.3+, and correctly bundles the major Python packages such as numpy, PyQt, Django, wxPython, and others.
- PyInstaller is tested against Windows, Mac OS X, and Linux. However, it is not a cross-compiler: to make a Windows app you run PyInstaller in Windows; to make a Linux app you run it in Linux, etc. PyInstaller has been used successfully with AIX, Solaris, and FreeBSD, but is not tested against them.
- What’s New This Release
- Release 3.0 is a major rewrite that adds Python 3 support, better code quality through use of automated testing, and resolutions for many old issues.
- Functional changes include removal of support for Python prior to 2.7, an easier way to include data files in the bundle (Adding Files to the Bundle), and changes to the “hook” API (Understanding PyInstaller Hooks).
- Installing in Windows
- For Windows, PyWin32 or the more recent pypiwin32, is a prerequisite. The latter is installed automatically when you install PyInstaller using pip or easy_install. If necessary, follow the pypiwin32 link to install it manually.
- It is particularly easy to use pip-Win to install PyInstaller along with the correct version of PyWin32. pip-Win also provides virtualenv, which makes it simple to maintain multiple different Python interpreters and install packages such as PyInstaller in each of them. (For more on the uses of virtualenv, see Supporting Multiple Platforms below.)
- When pip-Win is working, enter this command in its Command field and click Run:
- venv -c -i pyi-env-name
- This creates a new virtual environment rooted at C:\Python\pyi-env-name and makes it the current environment. A new command shell window opens in which you can run commands within this environment. Enter the command
- pip install PyInstaller
- Once it is installed, to use PyInstaller,
- Start pip-Win
- In the Command field enter venv pyi-env-name
- Click Run
- Then you have a command shell window in which commands such as pyinstaller execute in that Python environment.
- ***
- In more detail...
- Compile Standalone Executable
- In order to get .exe you have to run pyinstaller on Windows, to get Linux or Mac standalone, you have to compile your script on the corresponding platform.
- On Windows:
- You may use this line to compile fairly simple python scripts to standalone executables. Run the following command in cmd:
- pyinstaller --onedir --onefile --name="MyStandalone" --windowed --icon="C:\fav.ico" "C:\compile.py"
- Options:
- –onedir – Create a one-folder bundle containing an executable (default)
- –onefile – Create a one-file bundled executable.
- –name – Define name for the executable.
- –windowed – Prevents a console window from being displayed when the application is run.
- –icon=”C:\fav.ico” – Location to icon file that’s going to be used in standalone .exe
- “C:\compile.py” – Location to your python script file.
- Usually will compile in couple of seconds and at the end of the process location of the standalone file was displayed. Pyinstaller, by default creates standalone executable in current user’s home folder. My dist location was: C:\Users\MyUsername\dist. Your location should be similar.
- Compiled standalone by default saves in "/Users/username/Documents/dist/MyStandalone", you should be able to find yours in similar folder.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement