将软件包添加到“嵌入”的Python中Windows安装 [英] Adding packages to Python "embedded" installation for Windows

查看:420
本文介绍了将软件包添加到“嵌入”的Python中Windows安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档


嵌入式分发是一个包含最小Python
环境的ZIP文件。

The embedded distribution is a ZIP file containing a minimal Python environment.

听起来不错! Python的64位Windows嵌入式v3.6.5仅13MB。作为编译的替代方法,我想将一些python脚本以及在未安装Python的Win10机器上运行它们所需的最低要求一起压缩。

Sounds great! The 64-bit Windows embedded v3.6.5 of Python is only 13MB. As an alternative to compiling, I would like to zip some python scripts together with the minimum needed to run them on a Win10 machine that doesn't have Python installed.

现在,我几乎总是需要导入其他软件包来提供功能。但是,如果要与该嵌入式版本的Python一起发送python脚本,我无法确定该怎么做。例如,如果我的脚本使用numpy,如何在嵌入中包含该库?也就是说,这样我就可以在任何Win10机器上解压缩单个部署文件并立即执行我的脚本?

Now, I almost always need to import additional packages to provide functionality. But I can't determine how I should do this if I want to send out a python script together with this embedded version of Python. For example, if my script uses numpy, how can I include that library in this "embed?" I.e., so that on any Win10 machine I can unzip the single deployment file and immediately execute my scripts?

(常规 pip install numpy 似乎会创建一个超过50MB的Lib子目录!但是对于嵌入式部署,我不需要任何调试支持,也不需要大量文件中包含的任何东西。)

(A regular pip install numpy appears to create a Lib subdirectory that's over 50MB! But for an "embedded" deployment I don't need any support for debugging or whatever else is encompassed in that mass of files.)

推荐答案

有一种扩展Python嵌入式安装的方法。
我设法创建了Flask-ready包,我可以在目标计算机上解压缩并运行代码。
诀窍是安装 EXACT 相同 python版本(正常的全功能python)作为目标嵌入式小python。不仅是x86版本,而且还必须匹配x86。

There is a way to extend Python embedded installation. I managed to create Flask-ready package, that I can just unzip on target machine and run code. The trick is to install EXACT same python version (normal full blown python) as your target embedded small python. Not only version but x86, x64 has to match as well.

然后在普通python上从pip安装模块,请转到 NormalPython\Lib\ \site-packages ,然后将安装后出现的所有新文件复制到 EmbeddedPython\Lib
最后添加 Lib 到嵌入式python文件夹中的 pythonXX._pth

Then install modules from pip on normal python, go to NormalPython\Lib\site-packages and copy all new files that appear after installing to EmbeddedPython\Lib finally add Lib to pythonXX._pth inside Embedded python folder.

完全测试您的应用程序非常重要万一您错过了一些包裹。
同样,这对于将.exe也添加到Scripts文件夹的软件包不起作用。
您仍然可以将exe复制到Script文件夹,然后将其添加到可以解决问题的路径。

It's extremely important to fully test your application in case you miss some package. Also this would not work for packages that also add .exe to Scripts folder. You could still probably copy the exe's to Script folder and add it to path which could do the trick.

这篇关于将软件包添加到“嵌入”的Python中Windows安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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