How do you make an installer for your python progr

2020-08-26 10:59发布

Im new to python, but I was thinking about making a program with python to give to my friends. They don't know much about computers so if I asked them to install python by them selves they couldn't do it, but what if I could make an installer that downloads some version of python that only has what is needed for my file to run and make an exe file that would run the .py file in its own python interpreter . I also did a Google search and saw the freezing applications I could use to make the code into exe files to distribute (cx_freeze I use python 3.2), but not all of my friends have Windows computers and I rather Have my program so in each new version it auto updates by making a patch to .py file and not completely re-installing it .

** I am not looking for anything to make a stand alone executable . Just some kind of installer that bundles a minimalistic version of the python version your using . And an option to have an exe that is just a link to run the python file in the portable python interpreter, just for windows and a .sh file that would do the same for linux.

3条回答
劳资没心,怎么记你
2楼-- · 2020-08-26 11:26

Python is an interpreted, not a compiled language. So any standalone program you may want to distribute must bundle the entire interpreter inside it plus the libraries you used. This will result in an enormous file size for a single program. Also, this huge install cannot be used to run other python programs. An only marginally more complicated, but far better solution than this, is to just install the interpreter once and run any python program with it.

I understand that the point of your question was to make a standalone executable, so I know I'm not answering it. But not being able to create executable standalones is one of the caveats of interpreted languages. However, a fundamental point here is about the whole objective of an interpreted language, which is a single interpreter with all the generic functions required to run any python code (which now happily needn't be any longer than they need to be). So you see, it's not really a caveat, this was the whole intention of interpreted languages. You might finally find a way to create a standalone python executable that runs on your friends' computers, but that would defeat the entire framework and idea behind an interpreted language.

查看更多
\"骚年 ilove
3楼-- · 2020-08-26 11:36

Pyinstaller is a good option to convert them to an windows executable. You can install it in cmd.exe as admin and run pip install pyinstaller or pip install --pre pyinstaller.

you can then run it using pyinstaller. (sorry that i can't supply a automated script i wrote after a system restore. I'll write it again soon using pyqt5)

syntax

--onefile - puts the program and it's files into a exe.

--onedir - put your program into a directory (folder) (faster than --onefile as it does not need to extract files)

-c - create a console app.

-w - create an app without the console.

-i "[Path to .ico or exe with icon. e.g C:\Files\CODE\Icon.ico]" - create an app without the console.

you can read the rest here.

You can then get inno setup and create an offline installer.

If you need a web installer (it downloads a file and extracts it.) I am currently writing one and would be glad to create one for you.

查看更多
叼着烟拽天下
4楼-- · 2020-08-26 11:44

I am shocked that no answer mentions that py2exe now supports both Python 2.x and Python 3.x

https://pypi.python.org/pypi/py2exe#downloads

查看更多
登录 后发表回答