Use Python without installing

随声附和 提交于 2020-01-04 02:15:51

问题


I have an installer which uses a Python script to install several components. I do not want to install Python on the users computer if they do not already have it and I also do not want having Python installed to be a prerequisite for using my installer. Is there a way of downloading Python without using the installer and just running it from a directory which can be easily removed after the installation is complete?


回答1:


Portable Python is an easy tool to use on Windows. If you want to create .exe programs use PyInstaller to compile them. They can both work on top of each other, you can compile (make .exes) using Portable Python, Portable Python 3 is also available.




回答2:


If the installer is for OS X or Linux, Python shall be there usually. Otherwise

  • Lazy way: Detect if Python is existed. If not, ask user to install it as dependency. e.g. A link for python download page.

  • Rewrite your script. If the logic is not complicated, use some other build-in shell script is a good idea.

  • Static linking Python. Yes, static linking is evil. However, it's still an option. Found some project maybe helpful on github and google-code




回答3:


(In addition to Owens points). Use py2exe or one of the other exe builder utils for python on windows. On other platforms just use the python script.




回答4:


Try cx_Freeze

This program can freeze your python code into a .exe file and some other pyd files, it can be run without installing python.

NOTE: You will need to install python to freeze, but you don't need python to run the program.

You can download from here.

https://anthony-tuininga.github.io/cx_Freeze/index.html

TO FREEZE: make a file setup.py type

from cx_Freeze import setup, Executable

setup (name='NEW_EXE_FILE_NAME',
   executables = [Executable("xx.py")])

xx.py will be the python code you want to freeze.

command line: python setup.py build



来源:https://stackoverflow.com/questions/27210351/use-python-without-installing

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