Python embeddable zip

2019-02-02 03:39发布

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

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.

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

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

Add what you need, e.g 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.

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

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

and for django it would be:

env2/Scripts/python -m pip install django  

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.

Which is the difference between Python Virtualenv and Python embeddable?

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

1条回答
爷、活的狠高调
2楼-- · 2019-02-02 04:23

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?

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

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 sould make sense for people who want to distribute Python-based programs or who want to embed Python into their application.

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.

查看更多
登录 后发表回答