Python可嵌入的zip [英] Python embeddable zip

查看:456
本文介绍了Python可嵌入的zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在3.5.0版本中, Python.org 引入了一个称为 embeddedable zip的发行版文件.

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

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

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

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

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

我意识到可以使用 get-pip.py 安装pip,并且,多亏了pip,添加许多其他应用程序包很容易,尽管我仍然无法添加Tkinter(根据您的shell调整斜线):

I realised that it is possible to install pip with get-pip.py and, 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):

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

添加您所需的内容,例如 django :

Add what you need, e.g django:

env1/python -m pip install django  

鉴于大小(3.5.1-x64为6.5兆),我认为它可以方便地创建隔离的环境.

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.

实际上,一般的Python 文档表示

In fact the general Python documentation says that

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

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

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

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:

virtualenv env2

对于django,它将是:

and for django it would be:

env2/Scripts/python -m pip install django  

比较env1env2的内容,它们似乎具有相同的文件.唯一的显着区别是 Tkinter1 ,对于桌面应用程序而言,这并不重要.

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

Python Virtualenv和Python embeddable有什么区别?

Which is the difference between Python Virtualenv and Python embeddable?

具体来说,使用可嵌入的zip(env1)和Virtualenv(env2)创建的隔离Web应用之间有何区别?

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

推荐答案

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

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?

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

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

在ms-windows世界中,应用程序通常以整体独立实体的形式分发.相比之下,基本上每个UNIX风格都有一个有效的软件包管理系统,这使得拥有依赖于其他软件包的软件包变得更加容易.因此,如果您在UNIX中安装基于python的应用程序,则包管理系统将基本上为您安装Python(如果尚未安装).在ms-windows上,此功能无效.由于(出于技术原因)在ms-windows上编译和设置内容是痛苦 [1] [2]

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用户安装Canopy或Anaconda,因为它们附带了您可能需要的大多数外部模块.

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.

编辑截至2020年,python.org发行版已经走了很长一段路.您不再需要特殊的编译器,并且越来越多的模块为PyPI上的ms-windows分发预编译的二进制文件.因此,我对ms-windows用户的建议已更改:使用 python.org版本 Python .

Edit As of 2020, the python.org distribution 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 releases of Python.

这篇关于Python可嵌入的zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆