[英]How can I run my Python code on other system which doesn't have the required external library module?
I have built a Python application using an external library (lxml-module). 我已经使用外部库(lxml-module)构建了Python应用程序。 This runs fine in my system. 这在我的系统中运行良好。 Is there any way to compile this code or package this code, so that I can run it in another system which does not have this external library (lxml-module) module installed in it? 有什么方法可以编译此代码或打包此代码,以便可以在未安装此外部库(lxml-module)模块的另一个系统中运行它?
If possible please give me a little reference on *.pyd also? 如果可能的话,还请给我关于* .pyd的一些参考吗?
PyInstaller would be a good way to go to package your code. PyInstaller是打包代码的好方法。
It works in a configure/make/build workflow (before which you setup a small spec file with different kinds of options). 它在配置/制作/构建工作流程中起作用(在此之前,您使用不同的选项设置了一个小规格文件)。 The external package will be shipped along with your application. 外部软件包将与您的应用程序一起提供。
lxml is supported in PyInstaller: http://www.pyinstaller.org/wiki/SupportedPackages . PyInstaller支持lxml: http ://www.pyinstaller.org/wiki/SupportedPackages。
As for being able to compile your code on another machine, Marcin had a good suggestion. 至于能够在另一台机器上编译代码, Marcin提出了一个很好的建议。
You can always copy the module to your local path and import it from there. 您始终可以将模块复制到本地路径,然后从那里导入。 Kind of what django did for json
until it was included in the standard library. django为json
做的事情,直到它被包含在标准库中为止。
This could do the trick: 这可以达到目的:
try:
import lxml
except ImportError:
import myownmodules.lxml as lxml
I know this is the less "high tech" approach but if the problem is simple enough this is what I would do without a blink. 我知道这是不太“高科技”的方法,但是如果问题很简单,这就是我会眨眼做的。
Besides .... our buddy Tim seems to agree: "If the implementation is easy to explain, it may be a good idea." 除了....我们的好友蒂姆(Tim)似乎也同意:“如果实现易于解释,那可能是个好主意。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.