Advertisement
here2share

PyInstaller -- from PyPI: pip

Jul 25th, 2017
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.73 KB | None | 0 0
  1. PyInstaller Quickstart
  2.  
  3. Install PyInstaller from PyPI:
  4.  
  5. pip install pyinstaller
  6.  
  7.  
  8. Go to your program’s directory and run:
  9.  
  10. pyinstaller yourprogram.py
  11.  
  12.  
  13. This will generate the bundle in a subdirectory called dist.
  14.  
  15. 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.
  16.  
  17. 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.
  18. What’s New This Release
  19.  
  20. 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.
  21.  
  22. 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).
  23.  
  24.  
  25.  
  26. Installing in Windows
  27.  
  28. 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.
  29.  
  30. 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.)
  31.  
  32. When pip-Win is working, enter this command in its Command field and click Run:
  33.  
  34.     venv -c -i  pyi-env-name
  35.  
  36. 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
  37.  
  38.     pip install PyInstaller
  39.  
  40. Once it is installed, to use PyInstaller,
  41.  
  42.     Start pip-Win
  43.     In the Command field enter venv pyi-env-name
  44.     Click Run
  45.  
  46. Then you have a command shell window in which commands such as pyinstaller execute in that Python environment.
  47.  
  48. ***
  49.  
  50. In more detail...
  51.  
  52. Compile Standalone Executable
  53.  
  54. 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.
  55.  
  56. On Windows:
  57. You may use this line to compile fairly simple python scripts to standalone executables. Run the following command in cmd:
  58.    
  59. pyinstaller --onedir --onefile --name="MyStandalone" --windowed --icon="C:\fav.ico" "C:\compile.py"
  60.  
  61.  
  62. Options:
  63.  
  64. –onedir – Create a one-folder bundle containing an executable (default)
  65. –onefile – Create a one-file bundled executable.
  66. –name – Define name for the executable.
  67. –windowed – Prevents a console window from being displayed when the application is run.
  68. –icon=”C:\fav.ico” – Location to icon file that’s going to be used in standalone .exe
  69. “C:\compile.py” – Location to your python script file.
  70.  
  71. 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.
  72.  
  73. 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