Python 可嵌入 zip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37633550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:42:22  来源:igfitidea点击:

Python embeddable zip

pythonpython-3.xpip

提问by antonio

With the 3.5.0 release, Python.orghas introduced a distribution billed as embeddable zip file.

在 3.5.0 版本中,Python.org引入了一个名为 embeddable zip file 的发行版

Unfortunately the zipped file comes without a help file (not even a readme). The download pageon Python.org just lists it among the downloads.

不幸的是,压缩文件没有帮助文件(甚至没有自述文件)。Python.org 上的下载页面只是在下载中列出了它。

Apparently this is a portable Python distribution. It is anyway quite different in structure and size from the standard distribution using the installer.

显然这是一个可移植的 Python 发行版。无论如何,它在结构和大小上与使用安装程序的标准发行版完全不同。

I realised that it is possible to install pip with get-pip.pyand, thanks to pip, it is a breeze to add many other application packages, though I am still unable to add Tkinter (adjust slashes according to your shell):

我意识到可以使用get-pip.py安装 pip并且,感谢 pip,添加许多其他应用程序包变得轻而易举,尽管我仍然无法添加 Tkinter(根据您的 shell 调整斜杠):

curl https://www.python.org/ftp/python/3.x.x/python-3.x.x-embed-amd64.zip > epython.zip
unzip -o epython.zip -d env1
curl -L https://bootstrap.pypa.io/get-pip.py>env1/get-pip.py
env1/python env1/get-pip.py

Add what you need, e.g django:

添加您需要的内容,例如django

env1/python -m pip install django  

Given the size (6.5 Mega for the 3.5.1-x64), I think that it can be convenient as a means to create isolated environments.

鉴于大小(3.5.1-x64 为 6.5 Mega),我认为它可以方便地作为创建隔离环境的一种方式。

In fact the general Python documentationsays that

事实上,一般的 Python文档

the embedded distribution is (almost) fully isolated from the user's system, including environment variables, system registry settings, and installed package

嵌入式发行版(几乎)与用户系统完全隔离,包括环境变量、系统注册表设置和已安装的包

Given this, in Windows there are now two isolated Python environments, the second being the standard Virtualenv. The same process in Virtualenv is like follows:

鉴于此,在 Windows 中现在有两个独立的 Python 环境,第二个是标准的 Virtualenv。Virtualenv中的相同过程如下:

virtualenv env2

and for django it would be:

对于 Django,它将是:

env2/Scripts/python -m pip install django  

Comparing the contents of env1and env2, they appear to have the same files. The only significant difference is Tkinter1, which is anyway not much significant for desktop apps.

比较的内容env1env2,他们似乎有相同的文件。唯一显着的区别是Tkinter1,这对于桌面应用程序来说意义不大。

Which is the difference between Python Virtualenv and Python embeddable?

Python Virtualenv 和 Python embeddable 之间的区别是什么?

Specifically, which is the difference between the isolated web app created with the embeddable zip (env1) and Virtualenv (env2)?

具体来说,使用可嵌入的 zip ( env1) 和 Virtualenv ( env2)创建的独立 Web 应用程序之间的区别是什么?

采纳答案by Roland Smith

As you can see from the documentation, it is mainly meant for running Python based applications on ms-windows and for embedding Python in an application. As you can see, they left out tkinter. Maybe to keep the size down?

文档中可以看出,它主要用于在 ms-windows 上运行基于 Python 的应用程序以及将 Python 嵌入到应用程序中。如您所见,他们遗漏了tkinter. 也许要缩小尺寸?

Comparing it to a virtualenv doesn't make much sense, I think. They have completely different use cases.

我认为将它与 virtualenv 进行比较并没有多大意义。它们有完全不同的用例。

In the ms-windows world, applications are generally distributed as monolithic independant entities. In contrast, basically every UNIX flavor has a working package management system which makes it easier to have packages that depend on others. So if you install a python-based app in UNIX, the package management system will basically install Python for you if it isn't installed yet. On ms-windows this doesn't work. Several Python distributions for ms-windows have sprung up because (for technical reasons) compiling and setting up stuff on ms-windows is painful[1][2][3]compared to UNIX. So having an embeddable Python could make sense for people who want to distribute Python-based programs or who want to embed Python into their application.

在 ms-windows 世界中,应用程序通常作为整体独立实体分布。相比之下,基本上每个 UNIX 风格都有一个有效的包管理系统,这使得拥有依赖于其他包的包变得更容易。因此,如果您在 UNIX 中安装基于 Python 的应用程序,包管理系统基本上会为您安装 Python(如果尚未安装)。在 ms-windows 上这不起作用。ms-windows 的几个 Python 发行版如雨后春笋般涌现,因为(出于技术原因) 与 UNIX 相比,在 ms-windows 上编译和设置内容是痛苦的[1] [2] [3]。因此,对于想要分发基于 Python 的程序或想要将 Python 嵌入到他们的应用程序中的人来说,拥有一个可嵌入的 Python 是有意义的。

In general though I recommend that ms-windows users install either Canopy or Anaconda because they come with most of the external modules that you'll be likely to need.

一般来说,尽管我建议 ms-windows 用户安装 Canopy 或 Anaconda,因为它们带有您可能需要的大多数外部模块。

EditAs of 2020, the python.orgdistribution has come a long way; you don't need a special compiler for it anymore, and more and more modules distribute precompiled binaries for ms-windows on PyPI. So my recommendation for ms-windows users has changed: use the python.org releasesof Python.

编辑到 2020 年,python.org分发已经取得了长足的进步;你不再需要一个特殊的编译器,越来越多的模块在 PyPI 上为 ms-windows 分发预编译的二进制文件。所以我对 ms-windows 用户的建议已经改变:使用Python的python.org 版本