How to package Python Project into a standalone executable?

感情迁移 提交于 2021-02-20 02:27:32

问题


i wan't to release my python project, but when i send it to someone he is forced to install all the packages im using in my python project.

Is there any way to pack it or something, because maybe there are some users who are not that familiar with pip or python.

Regards


回答1:


PyInstaller

PyInstaller is a program that freezes (packages) Python programs into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. Its main advantages over similar tools are that PyInstaller works with Python 2.7 and 3.4—3.7, it builds smaller executables thanks to transparent compression, it is fully multi-platform, and use the OS support to load the dynamic libraries, thus ensuring full compatibility.

It work even if users do not have python installed.

Here an example from a github project. As you can see, you can download sources, but also a zip containing every package used to run your project. In this example, it contains many files, but you can package everything into a single .exe file.

How to use (Manual):

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.

You can use -onefile argument in order to generate the bundle with only a single executable file.

Case specific:

You asked how to get arguments send by the user. Here is some way to do it, more or less convenient:

  • Use input(),
  • Use a config file,
  • Use default parameter.



回答2:


If you want to deploy your application that has to be run on other machines. i REALLY suggest you to use docker. You will build a docker image in local that contain your application and all of the dependencies you need the user just has to install docker, get your docker image and run it on his machine. https://docs.docker.com/get-started/




回答3:


If you want to deploy a python application , you can use cx_freeze to package it. It will provide you a binary ready to execute



来源:https://stackoverflow.com/questions/54212814/how-to-package-python-project-into-a-standalone-executable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!